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 […]
Ansible
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 […]
Working with date and timestamp in Ansible
Getting the system timestamp is very useful in multiple types of scenarios while scripting. You can use it for just printing out the time for logging purpose, use it for naming a directory or use it in a conditional statement to control the flow of your program. Ansible provides access to the remote system time […]
Working with Ansible loop
Ansible loop provides a lot of methods to repeat certain tasks until a condition is met. A basic example which can be used to install a lot of Linux packages can be written like the below example. – name: Ansible Loop example apt: name: “{{ item }}” state: present with_items: – python3 – ca-certificates – […]
How to delete multiple files / directories in Ansible
There are multiple methods in Ansible by which you can delete a particular file or directory, delete all files in a directory, delete files using regex etc. The safe way is to use the Ansible file module. You can also use the shell module to achieve the task. But it is not idempotent and hence […]
Working with Ansible conditionals using the ‘when’ statement.
Conditionals are one of the fundamental parts of any programming languages so as to control the flow of execution. Ansible also provides a method for this using the ‘when’ clause. The basic ‘when’ operation is very easy. You just have to declare the condition against the when clause like below. when: ‘some condition’ You can use […]
How to do Arithmetic Operations in Ansible
You can use arithmetic calculations in Ansible using the Jinja syntax. This is helpful in many situations where you have stored the output of an operation, and you need to manipulate that value. All usual operation like addition, subtraction, multiplication, division, and modulo are possible. Let us start with an example. We will be using […]
Working with Linux services using Ansible Systemd and Service modules
Init process in Linux is the first process to start on boot, and it tracks all the system services and Daemons. Various Linux Distros have created different implementations of the standard init systems. Currently, the most popular init system adopted by various Linux distros is systemd. In Ansible, the systemd processes can be controlled by systemd […]
Introduction to Ansible APT Package and Repository
APT or Advanced Packaging Tool is the preferred package management toolset in Ubuntu. It allows you to install new packages, update them and remove the packages. In this session, we will go through 3 APT related command line tools which are helpful and their Ansible counterparts. Apt-get – All the basic package management operations can be done […]