1
我正在尝试使用Ansible手册来配置EC2实例,使用Postgres进行配置,然后配置另一个EC2实例并使用数据库服务器的IP地址在其上配置Web服务器。但是,我无法让我的网络服务器查看我的Postgres服务器的地址。在数据库角色中,我可以看到我正在设置一个事实,并且可以使用调试语句显示该值,但是当我尝试在Web服务器角色中显示它时,Ansible会出错。下面是我使用至今的文物:设置事实不承担角色
主要剧本:
---
- name: provision machines
hosts: local
connection: local
gather_facts: False
roles:
- { role: ec2, instance_type: 'm3.large', application: 'postgres' }
- name: provision machines
hosts: postgres
sudo: yes
roles:
- { role: postgres }
- name: provision machines
hosts: local
connection: local
gather_facts: False
roles:
- { role: ec2, instance_type: 't2.micro', application: 'webserver' }
- name: Install and configure Engage
hosts: webserver
sudo: yes
roles:
- { role: webserver }
角色/的Postgres /任务/ main.yml:
---
- debug: msg="{{ hostvars.localhost.ec2.instances[0].private_ip }}"
- name: capture Postgres IP address
set_fact:
postgres_ip: "{{ hostvars.localhost.ec2.instances[0].private_ip }}"
- debug: msg="The postgres IP address is {{ postgres_ip }}"
角色/ Web服务器/任务/主。阳明:
---
- debug: msg="{{ postgres_ip }}"
输出显示我,其实是越来越设置与Postgres的作用”
TASK: [postgres | debug msg="The postgres IP address is not-set"] *************
ok: [54.174.93.155] => {
"msg": "The postgres IP address is 172.31.10.196"
}
但是,在web服务器角色中,值是未定义的。
TASK: [engage | debug msg="{{ postgres_ip }}"] ********************************
fatal: [54.172.192.12] => One or more undefined variables: 'postgres_ip' is undefined
FATAL: all hosts have already failed -- aborting
这是我如何/在哪里定义“postgres_ip”的问题?还是有更好的方法来从一个角色获取价值并在另一个角色中使用它?