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
112 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
110 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
110 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
51 views
+13 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,380 points
145 views
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
26 views