Search code examples
ansibleamazon-ebs

How to tag EBS volume using Ansible?


I want to add name or tag property when adding/attaching a new EBS volume to EC2 instance, but I don't see ansible ec2_vol doing that. It only allows name: to attach existing EBS volume, not when creating new one. Probably there is other way around ?


Solution

  • I think you need to use the ec2_tag module after the volume has been created.

    (See documentation here http://docs.ansible.com/ansible/ec2_tag_module.html )

    You'll need the volume id, but the ec2_vol module returns that so you should be able to register the result.

    The first example of the ec2_tag module shows tagging a volume

    tasks:
    - name: tag a resource
      ec2_tag: resource=vol-XXXXXX region=eu-west-1 state=present
      args:
        tags:
          Name: ubervol
          env: prod