Created
February 21, 2020 02:40
-
-
Save sherwind/e0e1462aa9450593e7ab3cf8d958612f to your computer and use it in GitHub Desktop.
Using Ansible to expand an EBS volume
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: server | |
vars: | |
vol_new_size: 50 | |
vol_drive: /dev/sdf | |
tasks: | |
- name: Gathering ec2 metada facts | |
ec2_metadata_facts: | |
- name: Get EBS volume ID and size | |
delegate_to: 127.0.0.1 | |
become: no | |
ec2_vol: | |
region: "{{ ansible_ec2_placement_region }}" | |
instance: "{{ ansible_ec2_instance_id }}" | |
state: list | |
register: result | |
- set_fact: | |
vol_id: "{{ (result.volumes | selectattr('attachment_set.device', 'equalto', vol_drive) | list)[0].id }}" | |
vol_size: "{{ (result.volumes | selectattr('attachment_set.device', 'equalto', vol_drive) | list)[0].size }}" | |
when: | |
- not ansible_check_mode | |
- name: Expand EBS volume | |
delegate_to: 127.0.0.1 | |
become: no | |
command: aws --region "{{ ansible_ec2_placement_region }}" ec2 modify-volume --volume-id "{{ vol_id }}" --size "{{ vol_new_size }}" --output json | |
changed_when: False | |
when: | |
- not ansible_check_mode | |
- vol_new_size > vol_size | int | |
- name: Wait for volume modification to complete | |
delegate_to: 127.0.0.1 | |
become: no | |
command: aws --region "{{ ansible_ec2_placement_region }}" ec2 describe-volumes-modifications --volume-id "{{ vol_id }}" --output json | |
register: result | |
until: result.stdout.find('completed') != -1 or result.stdout.find('optimizing') != -1 | |
retries: 60 | |
delay: 5 | |
changed_when: False | |
when: | |
- not ansible_check_mode | |
- vol_new_size > vol_size | int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment