postgresql - 无法使用 Ansible postgresql_user 模块创建用户

标签 postgresql ansible

我有适用于虚拟机的 Ansible 剧本。 plyabook正在安装Postgresql DB,在postgresql.confpg_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/

相关文章:

filter - 在 ansible with_items 循环中根据条件跳过某些项目

postgresql - 如何更改 PostgreSQL 中的日期样式?

java - JPA 错误后从 PostgreSQL 连接关闭中恢复

ansible - 如何在环境变量 Ansible Playbook 中使用命令

ruby - Ansible 无法运行 npm 或 rake 命令

ansible - Mac 上Ansible 需要手动创建/etc/ansible/hosts 吗?

django - 在Django/Apache中的性能不佳

ruby-on-rails - capistrano 回滚会撤消迁移吗?

sql - 如何对单独的查询集执行数学公式

variables - Ansible 组变量优先级