Ansible: Comment Out & Uncomment Lines in a File
To comment out or uncomment lines in a file in automated deployments we can use the Ansible’s replace module. This module is used to replace all instances of a pattern within a file and perfectly suits...
View ArticleAnsible: Compare Version Numbers – Examples
As Ansible is widely used as an automated provisioning and deployment tool, it is quite often required to compare version numbers of different software components. For example, you may need to check...
View ArticleAnsible: Set Variable In Task
Variables in Ansible can be defined in many different places, such as in inventory, in playbooks, in reusable files, in roles, and at the command-line. Ansible also allows to set variables directly in...
View ArticleAnsible: `lsb_release` Variable
The lsb_release -sc command displays the release codename of a Linux distribution in a short format. You can often meet this command while adding APT repositories, e.g. sudo apt-add-repository "deb...
View ArticleAnsible: Run Shell Command on Remote Host
To run a command on a remote host we can use the Ansible’s shell module (or win_shell for Windows targets). By default, the shell module uses the /bin/sh shell to execute commands, but it is possible...
View ArticleAnsible: Create File With Content
Ansible has built-in modules that can be used to create an empty file or a file with a content. These common tasks can be easily done using the Ansible’s file module (or win_file for Windows targets)...
View ArticleAnsible: `Cat` File – Print/Read File Content
The cat command in Linux is used to print a file’s content to a standard output. Ansible can also be used to connect to a remote Linux or Windows host and print the content of a remote file or save it...
View ArticleAnsible Vault: Encrypt | Decrypt a String
Ansible files may often contain different secret strings e.g. passwords, tokens, keys etc., and the good practice is not to store them in a plain text but to encrypt them. This is especially important...
View ArticleAnsible Playbook “Dry Run”– Check Mode
An Ansible’s “dry run” or check mode feature is just a simulation of the execution of the ansible-playbook command. When the ansible-playbook command is executed in the check mode, it will not make any...
View ArticleAnsible: Skip Parameter If Variable Not Defined
In Ansible, if you run a task that has some module’s parameter with a variable that is not set you will get “The task includes an option with an undefined variable” error. If for some reason you can’t...
View Article