【发布时间】:2020-01-14 03:09:00
【问题描述】:
我正在关注 ansible 文档:https://docs.ansible.com/ansible/latest/modules/ec2_eip_module.html,以便为 ec2 实例提供新的弹性 IP。参数release_on_disassociation 是set 为yes 但解除关联后弹性IP 不释放。
首先,我使用弹性 IP 创建了 ec2:
- name: provision new instances with ec2
ec2:
keypair: mykey
instance_type: c1.medium
image: ami-40603AD1
wait: yes
group: webserver
count: 3
register: ec2
- name: associate new elastic IPs with each of the instances
ec2_eip:
device_id: "{{ item }}"
release_on_disassociation: yes
loop: "{{ ec2.instance_ids }}"
之后,弹性IP被解除关联:
- name: Gather EC2 facts
ec2_instance_facts:
region: "{{ region }}"
filters:
"tag:Type": "{{ server_type }}"
register: ec2
- name: disassociate an elastic IP with a device
ec2_eip:
device_id: '{{ item.instance_id }}'
ip: '{{ item.public_ip_address }}'
state: absent
when: item.public_ip_address is defined
with_items: "{{ ec2.instances }}"
ansible --version
ansible 2.8.4
Python 版本是 3.7.4
【问题讨论】:
标签: amazon-web-services ansible ansible-2.x elastic-ip