title: PostgreSQL failing peer authentication with Ansible
body: <p>I am running PostgreSQL 9.3 on FreeBSD. FreeBSD uses <code>pgsql</code> as the default system user for PostgreSQL. My <code>/usr/local/pgsql/data/pg_hba.conf</code> looks like this:</p>
  
  <pre><code># TYPE  DATABASE        USER            ADDRESS                 METHOD
  local   all             pgsql                                   peer
  local   all             all                                     md5
  host    all             all             127.0.0.1/32            md5
  host    all             all             ::1/128                 md5
  </code></pre>
  
  <p>With this configuration I can connect to the database as <code>pgsql</code> without a password.</p>
  
  <pre><code>$ su pgsql
  $ psql template1
  template1=# \l
                           List of databases
  ...
  </code></pre>
  
  <p>That works as intended.</p>
  
  <p>On a remote machine, I have an Ansible task to create a database on the FreeBSD server.</p>
  
  <pre><code>- name: Create the postgresql database
    postgresql_db: name=mydatabase login_user=pgsql
  </code></pre>
  
  <p>Executing this task fails with the error <code>Peer authentication failed for user "pgsql"</code>.</p>
  
  <pre><code>PLAY [web] ********************************************************************
  
  GATHERING FACTS ***************************************************************
  ok: [host.example.org]
  
  TASK: [database | Create the postgresql database] *****************************
  failed: [host.example.org] =&gt; {"failed": true}
  msg: unable to connect to database: FATAL:  Peer authentication failed for user "pgsql"
  
  
  FATAL: all hosts have already failed -- aborting
  </code></pre>
  
  <p>Why does this fail when peer authentication for the user <code>pgsql</code> is clearly working?</p>