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,040 points
438 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,170 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,040 points
92 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,040 points
366 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,040 points
2,230 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,040 points
788 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 26, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
961 views
+2 votes
1 answer
0 votes
1 answer
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,170 points
313 views