ansible - 将事实传递给另一台主机上的角色
问题描述
我有 2 个主机组:A 和 B。在主机组 B 上执行的角色需要对主机组 A 的 IP 地址做一些事情。如何使主机组 A 的 IP 地址可用于主机 B?
主机
[A]
example.host.a.com
[B]
example.host.b.com
部署.yml
---
- name: Gather ip address of host A
hosts: A
tasks:
- set_fact:
a_host_ip: "{{ ansible_eth0.ipv4.address }}"
- name: Debug result
hosts: A
tasks:
- debug:
msg: "Host A ip adress: {{ a_host_ip}}" # prints correct ip address
- name: Deploy role on host B that has to access host A ip address
hosts: B
gather_facts: true
serial: 1
roles:
- role: role_b
role_b/tasks/main.yml
---
# 1. try
- debug:
msg: "IP of host A: {{ a_host_ip }}" # Error: 'a_host_ip' is undefined
# 2. try
- debug:
msg: "IP of host A: hostvars['A'].a_host_ip" # Error: hostvars['A'] is undefined
# 3. try
- debug:
msg: "IP of host A: hostvars['A'].ansible_eth0.ipv4.address " # Error: hostvars['A'] is undefined
解决方案
推荐阅读
- python - 如何在 macOS 上编译一个简单的 swig-python 库?
- javascript - 新手到 electronjs:关于 contextBridge / 适当用法的问题
- c++ - 当 unique_ptr 设置为 nullptr 时,谁以及何时删除对象
- python - 带条件的开放式 CV 汽车检测
- python - 如何跳过返回错误消息的迭代
- css - 我想在不使用 vanilla CSS 的情况下将字体真棒图标(如星星颜色)更改为红色(默认为黑色)
- python - Discord.py - 如何获取与我的机器人在语音频道中的所有成员的数量?
- vaadin - 编辑网格时是否可以在 GridPro 上的 Vaadin 14 中显示保存/取消按钮
- c - strace:ld-linux 无法运行简单的测试二进制文件
- google-cloud-functions - 当我们在firebase功能+带有缓存的firebase托管上部署服务器端渲染(例如nuxt ssr)时如何解决版本不匹配问题