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 16 in Ansible by Darson
79 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 16 by Lavanya

Related Questions In Ansible

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

lineinfile module in Ansible

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

answered Jan 16 in Ansible by Emily
165 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
245 views
0 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 in Ansible by Anushri
23 views
0 votes
1 answer