我有适用于虚拟机的 Ansible 剧本。 plyabook正在安装Postgresql DB,在postgresql.conf
和pg_hba.conf
中设置连接参数。但是现在我想使用 postgresql_user
模块创建一个具有 REPLICATION
角色的新用户。但是在执行此操作时收到错误:
fatal: [10.0.15.20]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"db": "",
"encrypted": false,
"expires": null,
"fail_on_user": true,
"login_host": "",
"login_password": "",
"login_unix_socket": "",
"login_user": "postgres",
"name": "replicador",
"no_password_changes": false,
"password": null,
"port": "5432",
"priv": null,
"role_attr_flags": "REPLICATION",
"state": "present",
"user": "replicador"
},
"module_name": "postgresql_user"
},
"msg": "unable to connect to database: could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket \"/var/run/postgresql/.s.PGSQL.5432\"?\n"
}
我唯一能找到的就是我需要使用
become: yes
become_user: postgres
但它并没有改变什么
这是我的ansible任务:
- name: create repication user
become: yes
become_user: postgres
postgresql_user:
state: present
name: replicador
encrypted: no
role_attr_flags: REPLICATION
以及 postgresql.conf
中的 postgresql 设置
listen_addresses = '*'
和pg_hba.conf
host all all all trust
最佳答案
根据您的错误判断,postgres 正在尝试通过 unix 套接字而不是 tcp 连接到服务器。您应该将以下字符串添加到 pg_hba.conf
local all all trust
信任所有 unix 套接字连接或尝试将 login_host: 127.0.0.1
指定给 postgresql_user 角色。这部分实际上很奇怪,因为根据文档 login_host 默认为 localhost。
还要确保您的数据库确实在运行,以防万一您错过了剧本中的某个部分。
关于postgresql - 无法使用 Ansible postgresql_user 模块创建用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43756065/