lineinfile module in Ansible

0 votes

I have a file with has the following content

#crap

I want to uncomment it. How do I write a playbook for the following requirement?

Jan 16, 2019 in Ansible by Derryl
1,373 views

1 answer to this question.

0 votes

You can use the lineinfile module for this purpose. This module will search a file for a line, and ensure that it is present or absent. This is useful when you want to change a single line in a file only.

Something like this should work:

- name: test lineinfile
  lineinfile: backup=yes state=present dest=/etc/foo.txt
              regexp='^#crap'
              line='crap'
answered Jan 17, 2019 by Emily

Related Questions In Ansible

0 votes
1 answer

Importance of lineinfile module in Ansible.

Hi@akhtar, The lineinfile module will search a file ...READ MORE

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

How to replace a line using lineinfile module in Ansible?

Hi@MD, You can use lineinfile module in Ansible. ...READ MORE

answered Sep 2, 2020 in Ansible by akhtar
• 38,260 points
2,794 views
0 votes
1 answer
0 votes
1 answer

Using lxc_container module in ansible

This mostly happens when you've not installed ...READ MORE

answered Aug 10, 2018 in Ansible by DareDev
• 6,890 points
1,583 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,923 views
+2 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Add a node in Ansible

Follow these steps @Ruth: Generate ssh key ssh-keygen Check the ...READ MORE

answered Jan 8, 2019 in Ansible by Haider
1,423 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