Idempotency in an Inaccessible Play

I am setting up a server using Ansible playbook. My game works correctly in the very first execution, but when I run the same book again, it creates duplicate lines in the configuration file on the server. I am using the lineinfile module. An example of the following task adds a line every time I run a book.

 - lineinfile: dest=/etc/pam_ldap.conf line="ssl off" 

Is there a way to avoid this and maintain idempotency.

+5
source share
1 answer

Theoretically, lineinfile should work as you expect. A line is added only if it is not already present in the file.

Is the file a symlink? I do not see the reason why Ansible should not follow this link, but perhaps this could be the reason that it cannot identify the string.

Have you tried adding the regexp parameter? In any case, it will make sense to cover cases where a string like ssl on already exists.

 - lineinfile: dest=/etc/pam_ldap.conf line="ssl off" regexp="^ssl\s+" 
0
source

Source: https://habr.com/ru/post/1213226/


All Articles