Difference between revisions of "Gather facts"

From wikieduonline
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
[[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
 +
* https://docs.ansible.com/ansible/latest/user_guide/playbooks_vars_facts.html#ansible-facts
 +
 +
 +
* Collect facts: <code>gather_facts: [ no | yes ]</code>
 +
* Show gathered facts: <code>[[ansible localhost -m setup]]</code>
  
<code>gather_facts: [ no | yes ]</code>
+
- name: Show Gathered Facts
 +
    debug:
 +
      msg: "{{ ansible_facts }}"
  
 
Example:  
 
Example:  
Line 31: Line 38:
 
* <code>[[bolt task run facts --targets]]</code>
 
* <code>[[bolt task run facts --targets]]</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
 
 
* <code>[[ansible.builtin.set_fact]]</code> module
 
* <code>[[ansible.builtin.set_fact]]</code> module
  

Latest revision as of 13:50, 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


- name: Show Gathered Facts
   debug:
     msg: "Template:Ansible facts"

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[edit]

See also[edit]

Advertising: