ec2_vol repeatability

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

Sounds reasonable to me, anyone else have thoughts?

It’s certainly come up before, and lots of people are keen to have it

https://github.com/ansible/ansible/pull/4034
https://github.com/ansible/ansible/pull/5287

It looks like the tagging is in place so it would just be a matter of not creating the volume if a volume with that name tag already exists. However, there’s no AWS rule that the same name can’t be used for multiple volumes, so there should be an option to say ‘create even if name tag exists’, which should default to true (so that existing users of the name tag don’t get unexpected issues as a result)

Will

Will,

Thanks for the comments.

4034 was closed in favor of 5287.

Unfortunately, 5287 doesn’t provide the semantics we’re discussing, and in fact some of the behavior that was added by 5287 prevents those semantics. Example: lines 205-6 explicitly prevent using the name parameter if a volume size is specified under the assumption that named volumes are already created.

I don’t think the multiple name tag is an issue, as the current module in devel will not create volumes if a name tag is specified. The current module will also fail if more than one volume of the same name exists and the name parameter is specified.

Regards,
-scott

For comments:

https://github.com/ansible/ansible/pull/7171

Regards,
-scott