I just ran across the following in the module code while looking to see if it would do exactly this:
# Note: this module needs to be made idempotent. Possible solution is to use resource tags with the volumes.
# if state=present and it doesn't exist, create, tag and attach.
# Check for state by looking for volume attachment with tag (and against block device mapping?).
I’m willing to do this work since I need it today. I was thinking the following:
1) Use the existing Name tag functionality
2) If something like this is being done:
- name: Create log volume
local_action:
module: ec2_vol
instance: "{{ environment_instance.id }}"
device_name: "{{ rsyslog_log_device }}"
volume_size: "{{ rsyslog_log_volume_size }}"
name: "{{ rsyslog_log_volume_name }}"
region: "{{ vpc_region }}"
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
register: new_volume
a) Check if the volume exists by the Name tag
b) If not, create given the parameters, and tag
c) If not attached, do so
I believe that b (other than the tagging) and c are already there. I would just need to change the code to stop preventing name if size is specified, and do a create if the named volume doesn’t exist.
Comments?
Regards,
-scott