Creating new files is a pretty standard task in server scripts. In Ansible there are multiple methods to create new empty files. You can also set different permissions, different group permissions, set the owner of the file, create files with content in them etc. Let us go through some ways in which it can be […]
Ansible
Replacing Strings and Lines in Ansible
There are multiple ways in which you can replace a particular word, a line, all the words matching a specific pattern etc. in Ansible. Depending on the situation we can use the Ansible ‘replace’ module or ‘lineinfile’ module. In this post, we will see some examples of how to use these modules to get the desired […]
How to split strings and join them in Ansible
Split commands are useful when you need to divide a large line or a block of lines into a list. The dividing character will be specified in the command itself. So we can split when every ‘space’ character occurs, semicolon appears, a digit occurs etc. Join command is useful when you want values in a […]
How to uncomment/comment lines in files using Ansible
Uncommenting or commenting a line is usually a task of just adding character or removing a character at the front; Unless it is a block comment. Let us see a few ways of dealing with single line comments in Ansible. Commenting a line in Ansible using replace module Replace module in Ansible is used to […]
How to check if a file/directory exists in Ansible
To get the details of a file or directory in a Linux system, we can use the Ansible stat module. It works similar to the Linux ‘stat’ command. Of course, the module provides much more detail than whether a file exists or not. We can know when the file was last modified, what all permissions […]
How to Create a Directory in Ansible
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, […]
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 […]
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 […]