Ansible配置


Ansible Configuration
Precedence from lowest to highest
Configuration File
Find the first ‘a(chǎn)nsible.cfg’ in these locations in order:
Environment Variable: ANSIBLE_CONFIG
Current Directory
Home Directory ~/
/etc/ansible
Generate a sample file
ansible-config init --disabled > ansible.cfg
ansible-config init --disabled -t all > ansible.cfg
includes existing plugins
Environment Variables
Command-line options
Commands
ansible
ansible-config
ansible-console
ansible-doc
ansible-galaxy
ansible-inventory
ansible-playbook
ansible-pull
ansible-vault
Options
Help
ansible -h
ansible-playbook -h
... ...
For option that accepts only a single value, the last one wins
Eg:
ansible -m ping myhost -u mike -u carol
ansible -m ping myhost -u carol
For option that allow multiple values, append all
Eg:
ansible -i /path/inventory1 -i /path/inventory2 -m ping all
Playbook keywords
Eg, connection
Variables (Connection variables)
Set the specifics on how to execute actions on a target
ansible_become_user
ansible_connection
ansible_host
ansible_python_interpreter
ansible_user
Define
In inventory
In playbooks
Using extra variables at the command line
-e or --extra-vars
ansible -u carol -e 'ansible_user=brian' -a whoami all
brian