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 in Ansible by Derryl
90 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 16 by Emily

Related Questions In Ansible

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,810 points
88 views
0 votes
1 answer

Role of subelement module in an Ansible playbook

Hey @Rahul thanks for a better question ...READ MORE

answered Jan 16 in Ansible by Emily
83 views
0 votes
1 answer

Issue while using lineinfile module - Ansible

The lineinfile task has to match both the ...READ MORE

answered Jan 16 in Ansible by Lavanya
41 views
+13 votes
2 answers
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 in Ansible by Haider
14 views