5. Configure Ansible¶
5.1. Configure Ansible Core¶
one configuration file
nearly all parameters can be overridden in
ansible-playbookor with command line flagsthere are several places for configuration files, the first matches
- set the variable
ANSIBLE_CONFIGfor your config path - place a
ansible.cfgconfiguration file in the working directory - place a
.ansible.cfgconfiguration file in your home directory /etc/ansible/ansible.cfg
- set the variable
A short example of a configuration file.
[defaults]
inventory = hosts
[privilege_escalation]
become = True
become_method = sudo
become_user = root
Hint
There are some advanced configuration sections to tune Ansible: ssh_connection and accelerate
5.2. Configure a static inventory¶
- Inventory is the representation of information about hosts
- defines what groups a host belongs to
- a hierarchy of groups often results
- the inventory path can be set in the Ansible config file (
inventory =) - the static file is often named
hosts - the entries can be fqdn or ip-addresses
# static inventory file
srv.pascal.lab
web1.pascal.lab
5.2.1. Links¶
5.2.2. Host Groups¶
- the host group name is defined in brackets
[myhostgroup] - systems can be in more than one group
- variables can be set for a group of hosts in
group_vars - you can have groups of groups with
children: - INI-like format of the file
- don’t use dashes
-in group names
[zurich] <- group name zurich
web1.lab <- host in the group zurich
db1.lab
[berne]
web2.lab
db2.lab
[switzerland:children] <- group name switzerland
zurich <- sub-group in the group switzerland
berne
5.2.3. Inventory Patterns¶
- you can also define ranges for numbers or letters
[web]
web[01:25].lab
- intersections
webservers:&staging