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,440 points
2,479 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,230 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,440 points
590 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,440 points
2,921 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,440 points
13,306 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,440 points
5,376 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
3,522 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,230 points
1,027 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,230 points
2,256 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