This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
ansible:ansible_best_practice [2023/04/06 19:29] manu [Inventory] |
ansible:ansible_best_practice [2025/11/18 13:26] (current) manu |
||
|---|---|---|---|
| Line 2: | Line 2: | ||
| Reference: xavki (youtube) | Reference: xavki (youtube) | ||
| - | + | ||
| - | /etc/ansible/ansible.cfg | + | Use the command |
| + | <cli prompt='#'> | ||
| + | # ansible-config [init|list|view|dump|validate] | ||
| + | </cli> | ||
| + | |||
| + | **/etc/ansible/ansible.cfg** | ||
| <code> | <code> | ||
| [defaults] | [defaults] | ||
| + | inventory = /etc/ansible/inventory | ||
| host_key_checking = False # don't ask for accepting ssh keys | host_key_checking = False # don't ask for accepting ssh keys | ||
| callback_whithelist = profile_task # Print tasks duration | callback_whithelist = profile_task # Print tasks duration | ||
| forks = 30 # Parallel sessions | forks = 30 # Parallel sessions | ||
| + | log_path = ./ansible_log.txt | ||
| [ssh_connection] | [ssh_connection] | ||
| Line 19: | Line 26: | ||
| [defaults] | [defaults] | ||
| fact_caching = jsonfile | fact_caching = jsonfile | ||
| - | fact_caching_timeout = 3600 | + | fact_caching_timeout = 3600 # 1 hour |
| fact_caching_connection = /tmp/myfacts | fact_caching_connection = /tmp/myfacts | ||
| + | </code> | ||
| + | |||
| + | <code> | ||
| + | [defaults] | ||
| + | ask_pass = True | ||
| + | |||
| + | [privilege_escalation] | ||
| + | sudo_user = root | ||
| + | ask_sudo_pass = True | ||
| + | become = True | ||
| + | become_user = root | ||
| + | become_ask_pass = True | ||
| + | vault_password_file = /mypath/vault_file | ||
| + | |||
| </code> | </code> | ||
| Line 32: | Line 53: | ||
| </cli> | </cli> | ||
| + | === Using setup module === | ||
| + | |||
| + | Collect directly gather facts | ||
| + | <cli prompt='#'> | ||
| + | # ansible-playbook -i inventory.yml all -m setup | ||
| + | </cli> | ||
| + | |||
| + | Filter on a specific setting | ||
| + | <cli prompt='#'> | ||
| + | # ansible-playbook -i inventory.yml all -m setup -a "filter=ansible_user*" | ||
| + | </cli> | ||
| ===== Create a base folder structure ===== | ===== Create a base folder structure ===== | ||
| Line 53: | Line 85: | ||
| </cli> | </cli> | ||
| - | ==== Inventory ==== | + | ===== Inventory ==== |
| + | |||
| + | You can export the variable or use the default | ||
| + | <cli prompt='#'> | ||
| + | export ANSIBLE_HOSTS=~/hosts | ||
| + | </cli> | ||
| Inventory type file can be json, text or yml | Inventory type file can be json, text or yml | ||
| Line 104: | Line 141: | ||
| ansible_become_method=sudo | ansible_become_method=sudo | ||
| </cli> | </cli> | ||
| + | |||
| + | ==== Send result by mail ==== | ||
| + | |||
| + | |||