Distributions and ways to install
Two distributions :
– a community package called ansible = Ansible language and runtime + many collections (Ansible extensions)
– a minimalist language called ansible-core (called ansible-base in version 2.10) = Ansible language and runtime + short list of core modules and other plugins
Two main ways to install :
– OS package manager or from source (if version doesn’t match to your requirement)
– As a Python module with pip
User VS system installation
With pip, Ansible may installed globally or for a specific user.
Beware : the user installation doesn’t generate the /etc/ansible/ansible.cfg
file.
If required, we need to create it.
Installation
Install as user with pip
Install as user (while we may also install as system if we want to)
Create a dedicated user for :
useradd -m ansible
(create the user with a home dir)
usermod -s '/bin/bash' ansible
(set bash as default shell)
usermod -a -G sudo ansible
(optional : add the user as sudoer)
login as ansible and install :
pip3 install --user ansible
Ansible configuration files and inspect the ansible execution context
To know the execution context of ansible
That command allows to check that our execution context is the good one :
ansible --version
that outputs something like :
ansible [core 2.11.5] config file = None configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /home/ansible/.local/lib/python3.6/site-packages/ansible ansible collection location = /home/ansible/.ansible/collections:/usr/share/ansible/collections executable location = /home/ansible/.local/bin/ansible python version = 3.6.9 (default, Jan 26 2021, 15:33:00) [GCC 8.4.0] jinja version = 3.0.1 libyaml = True |
Look at config file = None
:
It means that no ansible.cfg file was found.
Multiple ways to set and override the Ansible configuration parameters
From the lower to the higher precedence :
– ansible.cfg sets the default configuration used by ansible
– configuration files for hosts and groups defined in host_vars/
and group_vars/
overrides the last one
– ansible-playbook overrides the last one
– command line flags overrides the last one
The ansible.cfg file
It is a file in a pseudo ini format.
Ansible searches that file in the following order (the first found is used):
ANSIBLE_CONFIG
(environment variable if set)
ansible.cfg
(in the current directory)
~/.ansible.cfg
(in the home directory)
/etc/ansible/ansible.cfg
If no file is found (we can check that with ansible --version
), Ansible uses a default configuration.
How to generate/rollback to the default ansible.cfg ?
Before Ansible 2.12 (core)
Check the file in the ‘stable’ git branche of the version used.
For example for Ansible 2.11 :
https://raw.githubusercontent.com/ansible/ansible/stable-2.11/examples/ansible.cfg
Since Ansible 2.12 (core)
You can generate it with ansible-config command :
ansible-config init --disabled > ansible.cfg
Custom host configuration