我想传递" private_dns_name"我的新创建的ec2实例在我的ansible playbook中的其他主机上。我尝试使用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
但是我在执行我的playbook时得到了public_dns变量未定义的错误。如何从新创建的ec2实例中检索/传递变量到另一个其他主机/ ec2实例?
答案 0 :(得分:0)
使用ansible magic variables访问其他主机的事实:
var bookName = document.getElementById('bookName').value;
firebase.database().ref('books/' + bookName + '/bookInfo').update({
bookTitle : bookName
});