Created at:
Modified at:
Ansible notes
Using ansible 2.10.7.
General tips
Generating a new vault
As simple as:
$ ansible-vault encrypt_string
If you don't want to type vault password, you may pass the
--vault-password-file filepath flag, or use the ANSIBLE_VAULT_PASSWORD_FILE
environment variable:
$ export ANSIBLE_VAULT_PASSWORD_FILE=filepath
$ echo -n password | ansible-vault encrypt_string
Debugging a variable
Just define a task like this:
- debug: var=variable_name
Running a playbook in Dry Run mode
Just append the -C flag:
$ ansible-playbook -C ...
Troubleshooting
Problems regarding Python version
(2025-11-16)
If you are running a newer version of Ansible against an older version of some operating system like CentOS 8, you might get errors similar to the one below:
Could not import the dnf python module using /usr/bin/python3.12 (3.12.8 (main, Dec 12 2024, 16:30:29) [GCC 8.5.0 20210514 (Red Hat 8.5.0-22)]). Please install `python3-dnf` package or ensure you have specified the correct ansible_python_interpreter. (attempted ['/usr/libexec/platform-python', '/usr/bin/python3', '/usr/bin/python'])
or this one:
Failed to import the required Python library (firewall) on <host>'s Python /usr/bin/python3.12. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter. Version 0.2.11 or newer required (0.3.9 or newer for offline operations
You need to downgrade Ansible to version 2.16 or older. This can be done setting a "virtual env" and install it:
python3 -m venv ~/venv-ansible-2.16
. ~/venv-ansible-2.16/bin/activate
pip install 'ansible-core<=2.16'
You might install some important collections, as well. Example:
ansible-galaxy collection install ansible.posix
See the next reference for details: