我正在尝试根据变量中的数字创建许多 AWS 弹性 IP - 到目前为止一切都很好。但是我需要检查这个 EIP 是否已经存在于我从文件中加载的一组变量中。如果 EIP 存在,我想跳过它的创建,例如:
- set_fact: "number_of_ips=3
- name: load the local config file
include_vars: profiles/{{ ec2_tag_environment }}/file_with_variables
- name: allocate a new elastic IP for server {{ item }} if not exists already
ec2_eip:
profile: "{{ boto_profile }}"
region: "{{ ec2_region }}"
state: present
register: reg_eip_server_{{ item }}
when: server_eip_{{ item }} is not defined
with_sequence: start=1 end={{ number_of_ips}}
(请不要介意缩进 - 它有效,但可能是复制/粘贴问题)在“何时”行我收到警告,如果我尝试使用它当然会失败,reg_eip_server_1.public_ip
因为它不存在
以下是问题:
- 有可能吗?
- 如何获取该项目的公共 IP 并在下一步中使用它?
- 当我使用这种计数时,如何使用条件跳过一个项目?