【发布时间】:2016-12-30 15:19:44
【问题描述】:
我想将我新创建的 ec2 实例的“private_dns_name”传递给我的 ansible 剧本中的其他主机。我曾尝试使用 set_fact 模块来定义变量,但没有运气!这是 host1 的 ansible playbook 条目
- name: new EC2 instance
hosts: host1
tasks:
- name: Launch the new EC2 Instance
ec2:
aws_access_key: "{{ aws_id }}"
aws_secret_key: "{{ aws_key }}"
group_id: "{{ security_group_id }}"
instance_type: "{{ instance_type }}"
image: "{{ image }}"
key_name: "{{ ssh_keyname }}"
wait: yes
wait_timeout: 900
region: "{{ region }}"
count: 1
instance_tags:
Name: Prod-Engineering
register: ec2
- name: Register public DNS fact
set_fact: public_dns= "{{ item.private_dns_name }}"
with_items: ec2.instances
在定义 set_fact 之后,我使用下面的示例代码将 private_dns_name 抓取到我的另一个 host2:
- hosts: host2
become: yes
tasks:
- command: ipa host-add "{{ public_dns}}" --password=xxxxx
但我在执行我的剧本时收到 public_dns variable not defined 错误。如何从新创建的 ec2 实例中检索/传递变量到另一个主机/ec2 实例?
【问题讨论】:
标签: amazon-ec2 ansible ansible-2.x