0

I am trying to automate the installation of a PostgreSQL database using Ansible.

However, the following task:

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

Results in this error:

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": []
}

The error in /var/lib/pgsql/9.6/initdb.log is:

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

What is interesting is that if I run sudo /usr/pgsql-9.6/bin/postgresql96-setup initdb on the host, it runs successfully...

Any help would be appreciated.

1 Answer 1

2

Try with PATH environment variable defined explicitly in the task:

- 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

Most likely the value of the path is set differently for interactive and non-interactive shell sessions.


Or locate the runuser executable and add the path before running the script:

command: PATH=/runuser/location:${PATH} /usr/pgsql-9.6/bin/postgresql96-setup initdb
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.