Ansible 2 Cloud Automation Cookbook
上QQ阅读APP看书,第一时间看更新

How to do it...

We can allocate and associate an Elastic IP address with an EC2 instance using an ec2_ip module. This will require the instance ID of the EC2 instance we want to associate this Elastic IP address with and the region of that instance as input parameters. 

- name: Allocate Elastic IP and associate it with an instance
ec2_eip:
device_id: "{{ item }}"
aws_access_key: "{{ access_key }}"
aws_secret_key: "{{ secret_key }}"
region: "{{ aws_region }}"
with_items:
- "{{ ec2_public_instance.instance_ids }}"
register: elastic_ip