Difference between revisions of "Gather facts"

From wikieduonline
Jump to navigation Jump to search
Line 28: Line 28:
 
* <code>[[ios_ping]]</code>
 
* <code>[[ios_ping]]</code>
 
* <code>[[bolt task run facts --targets]]</code>
 
* <code>[[bolt task run facts --targets]]</code>
* <code>[[set fact:]]</code>
 
 
* [[Chef]]: <code>[[inspec detect]]</code>
 
* [[Chef]]: <code>[[inspec detect]]</code>
 
* https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html#ansible-facts
 
* https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html#ansible-facts

Revision as of 21:22, 18 October 2022

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: