User Tools

Site Tools


ansible:ansible_best_practice

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ansible:ansible_best_practice [2023/04/06 19:17]
manu
ansible:ansible_best_practice [2025/01/13 17:37] (current)
manu
Line 9: Line 9:
 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 32: Line 33:
 </​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 65:
 </​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 85: Line 102:
     ungrouped: {}     ungrouped: {}
 </​cli>​ </​cli>​
 +
 +Another example
 +<cli prompt='#'>​
 +# vi /​etc/​ansible/​hosts
 +[servers]
 +server1 ansible_host=203.0.113.111
 +server2 ansible_host=203.0.113.112
 +server3 ansible_host=203.0.113.113
 +
 +[all:vars]
 +ansible_python_interpreter=/​usr/​bin/​python3
 +
 +[linux:var]
 +ansible_connection=ssh
 +ansible_ssh_user=ansible
 +ansible_ssh_pass=secret_password
 +ansible_python_interpreter='/​usr/​bin/​env python3'​
 +ansible_become_method=sudo
 +</​cli>​
 +
 +==== Send result by mail ====
 +
 +
  
ansible/ansible_best_practice.1680801478.txt.gz · Last modified: 2023/04/06 19:17 by manu