ec2_eip - associate an EC2 elastic IP with an instance.

Author:Lorin Hochstein <lorin@nimbisservices.com>

Synopsis

New in version 1.4.

This module associates AWS EC2 elastic IP addresses with instances

Options

parameter required default choices comments
ec2_access_key no
    EC2 access key. If not specified then the EC2_ACCESS_KEY environment variable is used.
    ec2_secret_key no
      EC2 secret key. If not specified then the EC2_SECRET_KEY environment variable is used.
      ec2_url no
        URL to use to connect to EC2-compatible cloud (by default the module will use EC2 endpoints)
        in_vpc no
          allocate an EIP inside a VPC or not (added in Ansible 1.4)
          instance_id no
            The EC2 instance id
            public_ip no
              The elastic IP address to associate with the instance.If absent, allocate a new address
              region no
                the EC2 region to use
                state no present
                • present
                • absent
                If present, associate the IP with the instance.If absent, disassociate the IP with the 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


                - name: associate an elastic IP with an instance
                  ec2_eip: instance_id=i-1212f003 ip=93.184.216.119
                
                - name: disassociate an elastic IP from an instance
                  ec2_eip: instance_id=i-1212f003 ip=93.184.216.119 state=absent
                
                - name: allocate a new elastic IP and associate it with an instance
                  ec2_eip: instance_id=i-1212f003
                
                - name: allocate a new elastic IP without associating it to anything
                  ec2_eip:
                  register: eip
                - name: output the IP
                  debug: msg="Allocated IP is {{ eip.public_ip }}"
                
                - name: provision new instances with ec2
                  ec2: keypair=mykey instance_type=c1.medium image=emi-40603AD1 wait=yes group=webserver count=3
                  register: ec2
                - name: associate new elastic IPs with each of the instances
                  ec2_eip: "instance_id={{ item }}"
                  with_items: ec2.instance_ids
                
                - name: allocate a new elastic IP inside a VPC in us-west-2
                  ec2_eip: region=us-west-2 in_vpc=yes
                  register: eip
                - name: output the IP
                  debug: msg="Allocated IP inside a VPC is {{ eip.public_ip }}"
                

                Note

                This module will return public_ip on success, which will contain the public IP address associated with the instance.

                Note

                There may be a delay between the time the Elastic IP is assigned and when the cloud instance is reachable via the new address. Use wait_for and pause to delay further playbook execution until the instance is reachable, if necessary.