Configure Ansible """"""""""""""""" Configure Ansible Core ====================== * one configuration file * nearly all parameters can be overridden in ``ansible-playbook`` or with command line flags * there are several places for configuration files, the first matches #. set the variable ``ANSIBLE_CONFIG`` for your config path #. place a ``ansible.cfg`` configuration file in the working directory #. place a ``.ansible.cfg`` configuration file in your home directory #. ``/etc/ansible/ansible.cfg`` A short example of a configuration file. .. code-block:: bash [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** Links ----- * http://docs.ansible.com/ansible/intro_configuration.html * `official Ansible config file `_ * `Ansible SSH Tuning `_ 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 .. code-block:: bash # static inventory file srv.pascal.lab web1.pascal.lab Links ----- * http://docs.ansible.com/ansible/intro_inventory.html * http://docs.ansible.com/ansible/latest/intro_patterns.html 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 .. code-block:: yaml [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 Inventory Patterns ------------------ * you can also define ranges for numbers or letters .. code-block:: yaml [web] web[01:25].lab * intersections ``webservers:&staging`` Links ----- * http://docs.ansible.com/ansible/intro_inventory.html#hosts-and-groups * http://docs.ansible.com/ansible/latest/user_guide/intro_patterns.html