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
36 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,520 points
69 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
62 views
+13 votes
2 answers
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
11 views
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.