Inventory
Initialization
Create inventory file with IP addresses. Check computers in inventory by doing a ping:
Inventory examples:
Configuration
Order of precedence for the config file:
- $ANSIBLE_CONFIG env variable (first place to be searched)
- ./ansible.cfg - local file in the working directory
- ~/.ansible.cfg - user home directory
- /etc/ansible/ansible.cfg - global config (last place to be searched)
First config file found wins, Ansible stops looking for other config files.
Environment override
Specify: $ANSIBLE_
Override settings on the fly:
[defaults] forks - how many parallel processes does Ansible handle. Default=5, production recommended=20
host_key_checking - check host key before sending commands. Default=True (for production), for dev/test systems =False (easy control)
log_path - Ansible logging. Default=Null, produstion recommended - set path all Ansible users can write to.
Target patterns
Patterns to choose hosts/groups:
- OR pattern: group1:group2
Example:
- NOT pattern: :!group2
- Wildcard pattern: web.lab.local*
- REGEX pattern: ~web[0-9]+
- AND pattern: group1:&group2 - apply to hosts BOTH in group1 and group2 (intersection)
- Complex patterns
Complex pattern example: webservers:&production:!python3 # apply to web servers in production but not in the Python3 group