title: Peer authentication failed using psql with user and db created with ansible postgresql_user
body: <p>What's wrong with my usage of ansible <code>postgresql_user</code>:</p>
  
  <pre><code> - name: Create user and grant access to the database
      become_user: postgres
      become: yes
      postgresql_user:
        db: '{{db_name}}'
        name: '{{db_user}}'
        password: '{{db_password}}'
        priv: ALL
        state: present
  </code></pre>
  
  <p>The database with proper name is created and when I enter psql being postgres user:</p>
  
  <pre><code>                                  List of databases
      Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges
  ------------+----------+----------+-------------+-------------+-----------------------
   app-andi | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
              |          |          |             |             | postgres=CTc/postgres+
              |          |          |             |             | andi=CTc/postgres
   postgres   | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 |
   template0  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |          |          |             |             | postgres=CTc/postgres
   template1  | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |          |          |             |             | postgres=CTc/postgres
  (4 rows)
  </code></pre>
  
  <p>problem:</p>
  
  <p>when trying to:</p>
  
  <p><code>psql -d "app-andi" -U andi -W</code> </p>
  
  <p>and providing password given in ansible variable I end up with:</p>
  
  <p><code>psql: FATAL:  Peer authentication failed for user "andi"</code></p>
  
  <p>USING:
  ansible 2.3.1.0
  Vagrant 1.9.4</p>
  
  <p>DOCS:
  <a href="http://docs.ansible.com/ansible/latest/postgresql_user_module.html" rel="nofollow noreferrer">http://docs.ansible.com/ansible/latest/postgresql_user_module.html</a></p>
  
  <p><a href="https://www.postgresql.org/docs/9.2/static/app-psql.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/9.2/static/app-psql.html</a></p>