ec2_tag - create and remove tag(s) to ec2 resources.

Author:Lester Wade

Synopsis

New in version 1.3.

Creates, removes and lists tags from any EC2 resource. The resource is referenced by its resource id (e.g. an instance being i-XXXXXXX). It is designed to be used with complex args (tags), see the examples. This module has a dependency on python-boto.

Options

parameter required default choices comments
aws_access_key no
    AWS access key. If not set then the value of the AWS_ACCESS_KEY environment variable is used.
    aws_secret_key no
      AWS secret key. If not set then the value of the AWS_SECRET_KEY environment variable is used.
      ec2_url no
        Url to use to connect to EC2 or your Eucalyptus cloud (by default the module will use EC2 endpoints). Must be specified if region is not used. If not set then the value of the EC2_URL environment variable, if any, is used
        profile no
          uses a boto profile. Only works with boto >= 2.24.0 (added in Ansible 1.6)
          region no
            region in which the resource exists.
            resource yes
              The EC2 resource id.
              security_token no
                security token to authenticate against AWS (added in Ansible 1.6)
                state no present
                • present
                • absent
                • list
                Whether the tags should be present or absent on the resource. Use list to interrogate the tags of an instance.
                validate_certs no yes
                • yes
                • no
                When set to "no", SSL certificates will not be validated for boto versions >= 2.6.0. (added in Ansible 1.5)

                Note

                Requires boto

                Examples


                # Basic example of adding tag(s)
                tasks:
                - name: tag a resource
                  local_action: ec2_tag resource=vol-XXXXXX region=eu-west-1 state=present
                  args:
                    tags:
                      Name: ubervol
                      env: prod
                
                # Playbook example of adding tag(s) to spawned instances
                tasks:
                - name: launch some instances
                  local_action: ec2 keypair={{ keypair }} group={{ security_group }} instance_type={{ instance_type }} image={{ image_id }} wait=true region=eu-west-1
                  register: ec2
                
                - name: tag my launched instances
                  local_action: ec2_tag resource={{ item.id }} region=eu-west-1 state=present
                  with_items: ec2.instances
                  args:
                    tags:
                      Name: webserver
                      env: prod
                

                Note

                The following environment variables can be used AWS_ACCESS_KEY or EC2_ACCESS_KEY or AWS_ACCESS_KEY_ID, AWS_SECRET_KEY or EC2_SECRET_KEY or AWS_SECRET_ACCESS_KEY, AWS_REGION or EC2_REGION, AWS_SECURITY_TOKEN

                Note

                Ansible uses the boto configuration file (typically ~/.boto) if no credentials are provided. See http://boto.readthedocs.org/en/latest/boto_config_tut.html

                Note

                AWS_REGION or EC2_REGION can be typically be used to specify the AWS region, when required, but this can also be configured in the boto config file