In Ansible it is recommended to set default values for variables to avoid undefined-variable errors: The task includes an option with an undefined variable. The default variables for a role can be defined in the defaults/main.yml file that might look something like this: nginx_version: 1.20.1 nginx_service_name: “nginx.service” Ansible will use the default values only if […]
To check whether the destination file exists and then run tasks based on its status, we can use the Ansible’s stat module (or win_stat for Windows targets). With this module we can identify not only whether the destination path exists or not but also if it is a regular file, a directory or a symbolic […]
Handlers in Ansible are special tasks that only get executed when triggered by another tasks via the notify directive. By default, handlers run not immediately but only after all the tasks in a particular play have been completed. This makes sense, as the handler will only run one time, regardless of how many tasks have […]
If you run an Ansible task that requires a privilege escalation, i.e. with become: true, you may get an error “sudo: a password is required”. This happens when Ansible needs to run some command with sudo but it doesn’t know the password. In this note i will show how to make the ansible-playbook command prompt […]
While attempting to install Ansible from an official APT repository, you may see a missing public GPG key error. This can happen when you add a repository, and you forget to add its public key. In this short note i am showing how to fix the GPG error NO_PUBKEY 93C4A3FD7BB9C367.
Ansible is a popular agent-less automation tool used to configure local or remote systems and deploy applications. The easiest way to install the latest version of Ansible on Ubuntu is to get it from the official APT repository. This short note shows how to install Ansible on Ubuntu, check its version, locate the configuration file […]
By default Ansible sends output of the plays, tasks and module arguments to STDOUT in the format that is not suitable for human reading. Starting from Ansible 2.5, the default output format can be changed to a human-readable using the callback plugin. This short note shows how to change the default Ansible’s JSON output format […]
It may be useful to run an Ansible playbook on a local system. For example for putting a playbook in a crontab or for a new host provisioning. In this note i am showing the several ways to run Ansible playbook locally.
During troubleshooting of Ansible issues it is useful to know how to enable debug mode and increase the level of verbosity. To enable debug and increase verbosity in Ansible you can pass the corresponding environment variables on the command line or define these settings in Ansible configuration file. Warning: The debug output can also include […]
In Ansible playbooks, it is often a good practice to test if a variable exists and what is its value. Particularity this helps to avoid different “VARIABLE IS NOT DEFINED” errors in Ansible playbooks. In this context there are several useful tests that you can apply using Jinja2 filters in Ansible. In this article, i’ll […]