I'm working on a role that only needs to gather a single fact.
Performance it's a concern and I know that gathering facts it's time-consuming.
I'm looking for some way to filter gather_facts
inside a playbook, this will allow me to gather only the required facts.
This is possible using the setup core module:
ansible -m setup -a 'filter=ansible_hostname' my_host
10.200.0.127 | success >> {
"ansible_facts": {
"ansible_hostname": "my_host"
},
"changed": false
}
It's possible to use this feature inside the playbook? Something like this?
- hosts: all
sudo: yes
gather_facts: True
filter: "filter=ansible_*"
PS: The code above throws syntax exception.
EDIT 1: If someone needs to get hostname there's also another useful variable inventory_hostname.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…