Reputation: 75
I am trying to access Ansible facts for a different host than my target host. Following is my sample playbook. But facts are not collected for util
server when I run the below play. Can someone help me, how can I access facts of a different server?
---
- hosts: build
gather_facts: yes
vars:
dist: "{{ hostvars['util']['ansible_facts']['distribution'] }}"
tasks:
- name: Demo Magic variables
debug:
var: "{{ dist }}"
Upvotes: 5
Views: 5205
Reputation: 44760
Simply gather the needed facts from your desired server prior to using them. The simplest solution:
---
- 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 }}"
Upvotes: 5