我正在尝试访问与我的目标主机不同的主机的 Ansible 事实。以下是我的示例剧本。但是当我运行下面的游戏时,不会为 util
服务器收集事实。谁能帮我,我怎样才能访问不同服务器的事实?
---
- hosts: build
gather_facts: yes
vars:
dist: "{{ hostvars['util']['ansible_facts']['distribution'] }}"
tasks:
- name: Demo Magic variables
debug:
var: "{{ dist }}"
最佳答案
在使用它们之前,只需从您想要的服务器收集所需的事实即可。最简单的解决方案:
---
- name: Gather facts from util server
hosts: util
- name: Do our job
hosts: build
vars:
dist: "{{ hostvars['util']['ansible_facts']['distribution'] }}"
tasks:
- name: Demo Magic variables
debug:
var: "{{ dist }}"
https://stackoverflow.com/questions/65266210/