You will need to create directories or folders in Ansible many times during may of the DevOps process. Although you could do create directories using shell or command module, ansible provides a better and safer method for creating directories using the ‘file’ module. Ansible Directory Creation example To create a directory using the file module, […]
Ansible
Working with Ansible User Module
Ansible user module helps us to manage user accounts in Linux systems including creating user accounts, deleting them, setting passwords, adding groups to each user, etc. How to create users in Ansible Let us first see how to write a basic task for creating a Linux user using the Ansible user module. There is only […]
Working with Ansible Register Variables
Ansible registers are used when you want to capture the output of a task to a variable. You can then use the value of these registers for different scenarios like a conditional statement, logging etc. The variables will contain the value returned by the task. The common return values are documented in Ansible docs. Some […]
The Basics of Ansible Variables
Variables are used to store values in programs and as the name suggests the values can be changed throughout the program. These values are essential to deciding the code flow. Ansible variables help to determine how the tasks execute on different systems based on the values assigned to these variables. Ansible variable names should be letters, […]
Using grep commands in Ansible tasks
Grep command is used on Linux/Unix to search for a particular pattern in a list of files. There is no Ansible grep module, but you can use the grep commands along with shell module or command module. We can store the results of the task and use it in various conditional statements, print them or use […]
Working with Ansible filters
You can use Ansible filters when you need to format data inside template expressions. You are provided with a set of filters that are shipped with Ansible and another set provided by Jinja2 template engine. You can also build your own filters. In the following sections, I will give a list of useful filters and […]
User inputs with Ansible Prompt with examples
Working with Ansible Prompts. Sometimes you need input from the user to decide how the playbook should run. Maybe you need to name a directory. Maybe there are plays written for installing multiple versions. And you can install one version based on the user input. Or there may be some data which is sensitive you […]
How to zip files and folders with Ansible
Working with Ansible archive module Until version 2.3, Ansible didn’t support an Archive module(It was available in the developer edition for some time though). Before that, we had to use the shell module or command module to zip a directory in Ansible. From 2.3 you can use the Ansible archive module to compress the files […]
Working with Ansible variables in conditionals
Variables are necessary when you need to store the output of a task and need to access it in some other tasks. They are mostly used when dealing with a conditional statement where you can opt to run the task based on the output of another task. Here I will show some examples of using […]
Using the Ansible find module to search for files/folder
Ansible find module is used when you need to retrieve a list of files in the remote server which matches some conditions like name, size, etc. You will have to provide the path(s) to the remote server where the search should be done. It also supports searching for directories and links. The module returns the list of […]