Difference between revisions of "Gather facts"

From wikieduonline
Jump to navigation Jump to search
Line 5: Line 5:
  
  
<code>gather_facts: [ no | yes ]</code>
+
* Collect facts: <code>gather_facts: [ no | yes ]</code>
 
 
 
* Show gathered facts: <code>[[ansible localhost -m setup]]</code>
 
* Show gathered facts: <code>[[ansible localhost -m setup]]</code>
  

Revision as of 13:49, 5 February 2024

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


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"


The following modules failed to execute: ansible.legacy.setup


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


Related terms

See also

Advertising: