Talk:Ansible: Difference between revisions

 
(4 intermediate revisions by the same user not shown)
Line 239:
 
* Define multiple values
nano* Refer to these using: users.test.first_name
 
nano users.test.first_name
users:
Line 251 ⟶ 250:
last_name: done
home_dir: /home/test2
 
= Facts =
 
* Contain discovered information about a host
* Can be used in conditional statements to make sure certain tasks run only if they are necessary.
* Setup module is used to gather fact information
ansible -i inventory servers -m setup
 
* Facts provide a lot of information, Filter them:
ansible -i inventory servers -m setup -a 'filter=ansible_kernel'
 
* Custom facts can be created to display information about a host.
* Create a file on the Managed Host:
sudo nano /etc/ansible/facts.d/servers.fact
[server_info]
profile = web_server
 
Check the facts:
ansible -i inventory servers -m setup -a 'filter=ansible_local'
 
= Inclusions =
 
* These make it easy to create a modular Ansible Setup.
* Main variables can be set in the master Ansible file, generic tasks can be defined in included files.
* Tasks can be included in a playbook from external YAML file using '''include''' directive.
* Variables can be included from YAML or JSON file using '''include_vars''' directive.