Difference between revisions of "Gather facts"

From wikieduonline
Jump to navigation Jump to search
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{lowercase}}
 
[[Ansible]] <code>gather_facts</code> [[Ansible module|module]], new in [[Ansible 2.8]] (May 2019), allows to gather useful variables about remote hosts that can be used in [[playbooks]]
 
[[Ansible]] <code>gather_facts</code> [[Ansible module|module]], new in [[Ansible 2.8]] (May 2019), allows to gather useful variables about remote hosts that can be used in [[playbooks]]
 
* https://docs.ansible.com/ansible/latest/modules/gather_facts_module.html
 
* https://docs.ansible.com/ansible/latest/modules/gather_facts_module.html
  
 +
<code>gather_facts: [ no | yes ]</code>
  
  gather_facts: no
+
Example:
gather_facts: yes
+
#!/usr/bin/env ansible-playbook
 +
 +
  - [[hosts:]] localhost
 +
  gather_facts: no
  
<pre>
 
TASK [Gathering Facts] *********************************************************************************************************
 
ok: [SERVER_NAME]
 
</pre>
 
  
 +
Using facts:
 
  tasks:
 
  tasks:
 
   - name: Shut down Debian flavored systems
 
   - name: Shut down Debian flavored systems
Line 16: Line 18:
 
     [[when:]] [[ansible_facts]]['os_family'] == "Debian"
 
     [[when:]] [[ansible_facts]]['os_family'] == "Debian"
  
 +
 +
 +
TASK [Gathering Facts] *********************************************************************************************************
 +
ok: [SERVER_NAME]
  
  

Revision as of 12:24, 21 October 2021

Ansible gather_facts module, new in Ansible 2.8 (May 2019), allows to gather useful variables about remote hosts that can be used in playbooks

gather_facts: [ no | yes ]

Example:

#!/usr/bin/env ansible-playbook

- hosts: localhost
  gather_facts: no


Using facts:

tasks:
 - name: Shut down Debian flavored systems
   ansible.builtin.command: /sbin/shutdown -t now
   when: ansible_facts['os_family'] == "Debian"


TASK [Gathering Facts] *********************************************************************************************************
ok: [SERVER_NAME]


Related terms

See also

Advertising: