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

标签 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,它会成功运行...

如有任何帮助,我们将不胜感激。

最佳答案

尝试使用在任务中明确定义的 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 session ,路径值很可能设置不同。


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

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

关于postgresql - 使用 Ansible 运行 postgresql96-setup initdb 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42289616/

相关文章:

Postgresql 序列

sql - 使用 postgresql,如何获得反射(reflect)重叠时间段的日期值

Ansible 用于从 FTP 下载文件

Ansible 循环直到条件匹配。

sql - 当 select 没有行时获取案例结果字段

json - 如何在 Postgresql 中将 JSONB 值转换为 bool 值?

Ansible 剧本 : print a message

ansible - 如何动态覆盖ansible.cfg中的默认变量?

python - 尽管安装了 Ansible,但找不到 boto3 和 botocore

Ansible - 更改或修改注册变量