Issue while using lineinfile module - Ansible

0 votes

I used this solution according to my problem statement - https://www.edureka.co/community/35835/lineinfile-module-in-ansible

it worked fine for the first time but when I executed it again it gave a weird unexpected output

Before executing the playbook

#legos

After 1st execution

legos

After 2nd execution

legos
legos

After 3rd execution

legos
legos
legos
Jan 17, 2019 in Ansible by Darson
708 views

1 answer to this question.

0 votes

The lineinfile task has to match both the commented and uncommented state of the line. This way it will uncomment #lego but will pass lego unchanged.

This task should do what you want:

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

Related Questions In Ansible

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,230 points
2,486 views
+1 vote
3 answers
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,265 views
0 votes
1 answer

lineinfile module in Ansible

You can use the lineinfile module for ...READ MORE

answered Jan 17, 2019 in Ansible by Emily
1,049 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,534 views
+2 votes
1 answer
0 votes
1 answer

Mention Kubernetes version while using it with ansible

Hey @Dustin, The default value for roles is kube_version: ...READ MORE

answered Jan 22, 2019 in Ansible by Anushri
595 views
0 votes
1 answer

style.css not getting executed while installing lamp stack using ansible

Hey @Kishore make sure, your folder directory ...READ MORE

answered Feb 9, 2019 in Ansible by Monish
580 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