使用Ansible运行postgresql96-setup initdb时出错

时间:2017-02-17 04:48:04

标签: postgresql ansible ansible-2.x

我正在尝试使用Ansible自动安装PostgreSQL数据库。

但是,以下任务:

- name: Initialize Postgres
  command: /usr/pgsql-9.6/bin/postgresql96-setup initdb
  become: true

导致此错误:

fatal: [nexus-staging.chop.edu]: FAILED! => {
    "changed": true,
    "cmd": "/usr/pgsql-9.6/bin/postgresql96-setup initdb",
    "delta": "0:00:00.043311",
    "end": "2017-02-16 23:39:12.512727",
    "failed": true,
    "invocation": {
        "module_args": {
            "_raw_params": "/usr/pgsql-9.6/bin/postgresql96-setup initdb",
            "_uses_shell": true,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "warn": true
        },
        "module_name": "command"
    },
    "rc": 1,
    "start": "2017-02-16 23:39:12.469416",
    "stderr": "",
    "stdout": "Initializing database ... failed, see /var/lib/pgsql/9.6/initdb.log",
    "stdout_lines": [
        "Initializing database ... failed, see /var/lib/pgsql/9.6/initdb.log"
    ],
    "warnings": []
}

/var/lib/pgsql/9.6/initdb.log中的错误是:

/usr/pgsql-9.6/bin/postgresql96-setup: line 140: runuser: command not found

有趣的是,如果我在主机上运行sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb,它会成功运行...

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:1)

尝试在任务中明确定义的PATH环境变量:

- name: Initialize Postgres
  command: /usr/pgsql-9.6/bin/postgresql96-setup initdb
  environment:
    PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  become: true

对于交互式和非交互式shell会话,路径的值很可能设置不同。

或找到runuser可执行文件并在运行脚本之前添加路径:

command: PATH=/runuser/location:${PATH} /usr/pgsql-9.6/bin/postgresql96-setup initdb