【问题标题】:How to release an AWS elastic IP with ansible?如何使用 ansible 发布 AWS 弹性 IP?
【发布时间】:2020-01-14 03:09:00
【问题描述】:

我正在关注 ansible 文档:https://docs.ansible.com/ansible/latest/modules/ec2_eip_module.html,以便为 ec2 实例提供新的弹性 IP。参数release_on_disassociationset 为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


    【解决方案1】:

    我认为release_on_disassociation: 可能是 AWS 功能,但即使是这样,这对您的情况也没有关系,因为该模块在 state: present 操作期间不会检查该参数。相反,它只参考该参数during state: absent

    所以我认为您需要将该参数从顶部 ec2_eip 移到底部:

    - name: disassociate an elastic IP with a device
      ec2_eip:
        device_id: '{{ item.instance_id }}'
        ip: '{{ item.public_ip_address }}'
        release_on_disassociation: yes
        state: absent
      when: item.public_ip_address is defined
      with_items: "{{ ec2.instances }}"
    

    【讨论】:

      猜你喜欢
      • 2020-01-08
      • 2018-03-09
      • 2016-02-19
      • 2016-10-16
      • 1970-01-01
      • 2021-05-05
      • 1970-01-01
      • 1970-01-01
      • 2019-01-15
      相关资源
      最近更新 更多