使用psql进行对等身份验证失败,使用用ansible postgresql_user创建的用户和数据库

时间:2017-10-04 15:12:23

标签: postgresql vagrant ansible

我对ansible postgresql_user的使用有什么问题:

 - 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

创建具有正确名称的数据库,当我输入psql为postgres用户时:

                                  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)

问题:

尝试:

psql -d "app-andi" -U andi -W

并提供在ansible变量中给出的密码我最终得到:

psql: FATAL: Peer authentication failed for user "andi"

使用: ansible 2.3.1.0 Vagrant 1.9.4

DOCS: http://docs.ansible.com/ansible/latest/postgresql_user_module.html

https://www.postgresql.org/docs/9.2/static/app-psql.html

1 个答案:

答案 0 :(得分:0)

问题完全无关联。

只需像这样连接:

psql -d "app-andi" -U andi -W -h 127.0.0.1