'Ansible is there a modify-volume task?
I want to use ansible to run modify-volume and increase the volume size of instances with multiple ebs volumes attached. However, it seems that the ec2_vol task does not have a modify feature. How can I resize attached volumes using ansible?
Solution 1:[1]
There are a couple of answers, depending on your interest in "pure ansible:"
use the
shell:
task and spawnaws
a bunch of times to figure out what the state is of the volume, and then usemodify-volume
if necessaryuse a hybrid approach to use
ec2_vol_facts:
followed bycommand: aws ec2 modify-volume ...
if necessary"fork" the
ec2_vol.py
into yourplaybook/library
and update your copy to accept volume-id and size and call themodify_volume
equivalent there. You can then optionally submit that change back to ansible as a PR and see if they accept it so others can benefitAnsible will see your
ec2_vol.py
and supersede the globally installed one, which is good in that you get to continue to use all theec2_vol
behavior, and bad in that other people who read the playbook may wonder what's going on with that new behavior
Ansible is nice in that you can do things several ways, and suboptimal in that their release cycle and PR acceptance leaves much to be desired
Solution 2:[2]
This is an old question, but it's worth revisiting since now it's possible to do modify a volumes with Ansible only.
The following playbook will resize first EBS volume attached to a running instance.
---
- name: Prepare
hosts: all
gather_facts: false
tasks:
- block:
- name: Gather information about a particular instance using ID
amazon.aws.ec2_instance_info:
filters:
tag:Name: "{{ ansible_host }}"
instance-state-name:
- running
register: instance_info
- name: Resize volume
amazon.aws.ec2_vol:
instance: "{{ instance_info.instances.0.instance_id }}"
id: "{{ instance_info.instances.0.block_device_mappings.0.ebs.volume_id }}"
modify_volume: true
volume_size: "{{ ec2_instance_volume_size }}"
register: resize_volume
delegate_to: localhost
- name: Reboot if volume is resized so partition is resized by cloud-init
reboot:
when: resize_volume.changed
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |
Solution 2 | madrover |