clay
clay

Reputation: 20470

Ansible Create Tagged Volumes on EC2

In this snippet from my Ansible Playbook, I am tagging the EC2 instance itself in the instance_tags section, but is there any way that I can tag the created volumes?

In the docs (http://docs.ansible.com/ansible/latest/ec2_module.html), it seems the answer is no, but I wanted to ask here to make sure.

tasks:
- name: EC2 Instance
  ec2:
    aws_access_key: <hidden>
    aws_secret_key: <hidden>
    instance_type: c4.4xlarge
    image: ami-221ea342
    monitoring: yes
    region: us-west-2
    wait: yes
    volumes:
        - device_name: /dev/xvda
          volume_type: gp2
          volume_size: 80
        - device_name: /dev/xvdf
          volume_type: gp2
          volume_size: 500
    exact_count: 2
    count_tag:
      Component: "MyEC2"
      Environment: Production
      <snip>
    instance_tags:
      Component: "MyEC2"
      Environment: Production
      <snip>

Upvotes: 1

Views: 310

Answers (2)

nmarchini
nmarchini

Reputation: 141

You could achieve this if you switched to using Terraform instead of Ansible to create the AWS resources.

Upvotes: 1

helloV
helloV

Reputation: 52463

Unfortunately there is no support. You have to use ec2_tag after launching the instance. I expect a future Ansible release to support this since AWS recently (Mar 28, 2017) announced API/CLI support for tagging instances and volumes when launching.

See: Amazon EC2 and Amazon EBS add support for tagging resources upon creation and additional resource-level permissions

Upvotes: 1

Related Questions