Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Idempotency in ansible playbook

I am configuring a server using Ansible playbook. My playbook works properly at the very first execution but when I run the same playbook again it creates the duplicates lines in the configuration file on the server. I am using lineinfile module. Example following task adds the line each time I run the playbook.

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

Is there a way to avoid this, and maintain idempotency.

like image 229
yogeshagr Avatar asked Nov 10 '22 19:11

yogeshagr


1 Answers

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

Is the file a symlink? I don't see a reason why Ansible shouldn't follow that link, but maybe that might be a reason why it fails to identify the line.

Did you try to add a regexp parameter? It would make sense anyway, to cover cases where a line like ssl on already is present.

- lineinfile: dest=/etc/pam_ldap.conf
              line="ssl off"
              regexp="^ssl\s+"
like image 162
udondan Avatar answered Dec 25 '22 16:12

udondan