2017-05-03 120 views
0

我有适用于虚拟机的Ansible操作手册。 plybook正在安装Postgresql DB,在postgresql.confpg_hba.conf中设置连接参数。但是现在我想使用postgresql_user模块创建一个REPLICATION角色的新用户。但这样做时收到错误的:无法使用Ansible创建用户postgresql_user模块

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设置在postgresql.conf

listen_addresses = '*' 

而且pg_hba.conf

host  all   all  all   trust 

回答

1

通过你的错误的Postgres来看试图通过Unix套接字,而不是一个TCP连接到服务器。您应该将以下字符串添加到pg_hba.conf

local all    all          trust 

信任所有Unix套接字连接或尝试指定login_host: 127.0.0.1到postgresql_user作用。这部分实际上很奇怪,因为根据文档login_host默认为localhost。

并且还要确保您的数据库真的在运行,以防万一您遗漏了您的手册中的某个部分。

+0

即使我有应该重新启动postgresql的处理程序,并且它被触发了,但是当我尝试创建用户时,看起来没有启动它。我在postrgesql服务启动任务之后移动它并且它工作。谢谢! –