In this post, we are going to see how to use Ansible lineinfile module to replace multiple Lines at the same time. How to use Multiple Regular Expressions or Regex at the same time. How to Match Multiple lines. For this example, we are going to take apache httpd.conf file[...]
Read moreCategory: Ansible
Ansible lineinfile examples - Add, Modify, Delete, Replace lines
Ansible lineinfile module could be the saviour of your day when you want to work with files and especially modify their content on the run, like adding a new line in the file or updating a line in the file or replace a line in the file when certain text[...]
Read moreAnsible get ip address of current host or target
How to get the IP address of the current or remote host in Ansible. That's the question, this article is going to address. While running a Playbook you might have had a requirement where you need to get the IP address of the connected and current remote host. There are[...]
Read moreAnsible replace line in file - Ansible Replace Examples | Devops Junction
This article is about "how to replace a line in file using ansible and seeing various other examples of ansible replace module". Ansible facilitates us with a dedicated module named as replace The working principle of this module is more like find and replace in your favourite editor and it also supports[...]
Read moreAnsible AD HOC Command Examples - Ansible Cheat Sheet | Devops Junction
Ansible ad hoc commands are one-liners designed to achieve a very specific task they are like quick snippets and your compact swiss army knife when you want to do a quick task across multiple machines. To put simply, Ansible ad hoc commands are one-liner Linux shell commands and playbooks are[...]
Read moreansible search for string in file or check if string exists in file
The Objective of this post is to show how to search for a string in a file with ansible. ansible provides various ways to accomplish the same. We will cover, three major ways to search for a string in a file. Lineinfile module Using the Shell module and grep command[...]
Read moreansible update /etc/hosts file with IP of all hosts across all hosts
In Ansible, SSH Communication is everything. Let it be connecting to remote servers from your controller laptop/desktop (mac/windows) or to enable connectivity between servers on the host group. Especially this will be a huge task to accomplish when you do not have a DNS where each remote host can easily[...]
Read moreAnsible fail with custom message example
The Objective If you are a pioneer of Ansible, you might have come across or had this question "How to print a custom message with fail or failed_when" or "How to print a custom error message in case of failure" while running the ansible-playbook. What is so fun in displaying the built-in[...]
Read moreAnsible Reboot system and wait_for reboot to complete
The Objective The purpose of this post is to explain with an example of how ansible initiate the reboot and wait for the reboot to complete There are cases where we want our remote nodes to be rebooted or restarted. For example, Take the Patching as an example. As part[...]
Read moreAnsible wait_for module examples - How to | Devops Junction
Introduction to Ansible wait_for module Ansible wait_for module can be used to pause your playbook execution and to wait for many different things or conditions before continuing with the execution. The wait_for module of ansible is to make your playbook or task execution halt or pause for various reasons and for[...]
Read more