Difference between revisions of "Gather facts"

From wikieduonline
Jump to navigation Jump to search
 
(26 intermediate revisions by 4 users not shown)
Line 1: Line 1:
[[Ansible]] <code>gather_facts</code> module, new in [[Ansible 2.8]] (May 2019), allows to gather useful variables about remote hosts that can be used in [[playbooks]]
+
{{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]]
 
* 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
  
  
gather_facts: no
+
* Collect facts: <code>gather_facts: [ no | yes ]</code>
gather_facts: yes
+
* Show gathered facts: <code>[[ansible localhost -m setup]]</code>
  
<pre>
+
- name: Show Gathered Facts
TASK [Gathering Facts] *********************************************************************************************************
+
    debug:
ok: [SERVER_NAME]
+
      msg: "{{ ansible_facts }}"
</pre>
 
  
 +
Example:
 +
#![[/usr/bin/env ansible-playbook]]
 +
 +
- [[hosts:]] localhost
 +
  [[gather_facts:]] no
 +
 +
 +
Using facts:
 
  tasks:
 
  tasks:
 
   - name: Shut down Debian flavored systems
 
   - name: Shut down Debian flavored systems
Line 16: Line 25:
 
     [[when:]] [[ansible_facts]]['os_family'] == "Debian"
 
     [[when:]] [[ansible_facts]]['os_family'] == "Debian"
  
 +
 +
[[The following modules failed to execute: ansible.legacy.setup]]
 +
 +
 +
TASK [Gathering Facts] *********************************************************************************************************
 +
ok: [SERVER_NAME]
  
  
 
== Related terms ==
 
== Related terms ==
 +
* <code>[[gathering]]</code> in <code>[[/etc/ansible/ansible.cfg]]</code>
 
* <code>[[ios_ping]]</code>
 
* <code>[[ios_ping]]</code>
 
+
* <code>[[bolt task run facts --targets]]</code>
 +
* [[Chef]]: <code>[[inspec detect]]</code>
 +
* <code>[[ansible.builtin.set_fact]]</code> module
  
 
== See also ==
 
== See also ==
 
* Ansible <code>setup</code> module: https://docs.ansible.com/ansible/latest/modules/setup_module.html
 
* Ansible <code>setup</code> module: https://docs.ansible.com/ansible/latest/modules/setup_module.html
 
* {{Ansible modules}}
 
* {{Ansible modules}}
* {{Ansible}}
 
  
 
[[Category:Ansible]]
 
[[Category:Ansible]]
[[Category:Server administration]]
 

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: