I wrote a playbook to make a config edit in 
/etc/postgreql/95/main/pg_hba.conf.

Basically, it's to search for an existing string and replace it. 

Trouble is, when the playbook is ran for a second time, it adds the line as 
if it didn't exist.

Thoughts?

- name: postgres | Allow MD5 authentication
  lineinfile: >
    dest=/etc/postgresql/9.5/main/pg_hba.conf
    regexp="local\s+all\s+all\s+peer"
    line="local {{database.name}} {{database.user}} md5"
    backup=yes
    state=present
    insertafter=yes


----pg_hba.conf before running playbook
# Database administrative login by Unix domain socket
local   all             postgres                                peer

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local             all               all                   peer <---- to be 
changed
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
--------------------------------------------------------------------------------------------

----pg_hba.conf after running playbook once
# Database administrative login by Unix domain socket

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local             sandbar               sandbar                   peer 
<----------Good
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
--------------------------------------------------------------------------------------------

----pg_hba.conf after running playbook twice
# "local" is for Unix domain socket connections only
local             sandbar               sandbar                   peer 
<----------Good
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5
local             sandbar               sandbar                   peer 
<----------Duplicate
--------------------------------------------------------------------------------------------




-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/1d74af28-b761-4ae4-8470-205fec429c2a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to