How to replace a line using lineinfile module in Ansible

0 votes

Hi Guys,

I have one file in a remote system. I want to replace one line in this file. How can I do that in Ansible Playbook?

Sep 2, 2020 in Ansible by MD
• 95,460 points
2,872 views

1 answer to this question.

0 votes

Hi@MD,

You can use lineinfile module in Ansible. This module has the capability to support regex expression. So you can create a regular expression and do your task as shown below.

- name: Replace a localhost entry with our own
  lineinfile:
    path: /etc/hosts
    regexp: '^127\.0\.0\.1'
    line: 127.0.0.1 localhost
answered Sep 2, 2020 by akhtar
• 38,260 points

Related Questions In Ansible

0 votes
1 answer

How to add several lines in a file using lineinfile module?

Hi@akhtar, When we need to perform a task ...READ MORE

answered Sep 2, 2020 in Ansible by MD
• 95,460 points
846 views
0 votes
1 answer

How to start httpd service in a remote system using Ansible?

Hi@akhtar, Ansible has a module named service. This ...READ MORE

answered Jul 30, 2020 in Ansible by MD
• 95,460 points
3,426 views
0 votes
1 answer

How to overwrite the content of a file in remote systems using Ansible playbook?

Hi@akhtar, You can find one argument in the ...READ MORE

answered Aug 2, 2020 in Ansible by MD
• 95,460 points
14,485 views
0 votes
1 answer

How to find the memory of remote systems using the setup module in Ansible?

Hi@akhtar, You need to use the setup module to ...READ MORE

answered Aug 10, 2020 in Ansible by MD
• 95,460 points
5,914 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,062 views
+2 votes
1 answer
0 votes
1 answer

How to create a simple S3 bucket on Ceph Rados Gateway using Ansible Playbook?

Hi@MD, Ansible has one module that can create ...READ MORE

answered Dec 4, 2020 in Ansible by akhtar
• 38,260 points
1,330 views
0 votes
1 answer

ansible ssh and user module issue with edureka VM

Hi@Konakanchl, I guess you need to give your ...READ MORE

answered Jul 23, 2020 in Ansible by akhtar
• 38,260 points
2,863 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP