gpt4 book ai didi

PostgreSQL 使用 Ansible 进行对等身份验证失败

转载 作者:行者123 更新时间:2023-11-29 11:06:55 25 4
gpt4 key购买 nike

我在 FreeBSD 上运行 PostgreSQL 9.3。 FreeBSD 使用 pgsql 作为 PostgreSQL 的默认系统用户。我的 /usr/local/pgsql/data/pg_hba.conf 看起来像这样:

# 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

通过此配置,我可以以 pgsql 身份连接到数据库,无需密码。

$ su pgsql
$ psql template1
template1=# \l
List of databases
...

按预期工作。

在远程机器上,我有一个 Ansible 任务要在 FreeBSD 服务器上创建一个数据库。

- name: Create the postgresql database
postgresql_db: name=mydatabase login_user=pgsql

执行此任务失败并出现错误 Peer authentication failed for user "pgsql"

PLAY [web] ********************************************************************

GATHERING FACTS ***************************************************************
ok: [host.example.org]

TASK: [database | Create the postgresql database] *****************************
failed: [host.example.org] => {"failed": true}
msg: unable to connect to database: FATAL: Peer authentication failed for user "pgsql"


FATAL: all hosts have already failed -- aborting

当用户 pgsql 的对等身份验证显然有效时,为什么会失败?

最佳答案

这对我有用:

- name: Create postgres database
become: true
become_user: postgres
postgresql_db:
name: <database-name>

在您的特定情况下,用户可能是 pgsql,但我认为通常用户是 postgres

关于PostgreSQL 使用 Ansible 进行对等身份验证失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25751085/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com