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
370 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, 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 in Ansible by MD
• 56,440 points
27 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 in Ansible by akhtar
• 25,030 points
41 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,850 points
449 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
676 views
+2 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
70 views