ansible-role-postgresql icon indicating copy to clipboard operation
ansible-role-postgresql copied to clipboard

Error Initializing Database

Open pyrodie18 opened this issue 3 years ago • 2 comments

When running the role, I receive an error on step TASK [geerlingguy.postgresql : Ensure PostgreSQL database is initialized.]

Ansible Information

[root@localhost devel]# ansible --version
ansible [core 2.12.2]
  config file = None
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.9.7 (default, Sep 21 2021, 00:13:39) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
  jinja version = 3.0.3
  libyaml = True

Playbook

- name: Install Database
  hosts: rocky-8

  roles:
    - role: geerlingguy.postgresql
      become: true

Play Output

TASK [geerlingguy.postgresql : Ensure PostgreSQL database is initialized.] ***********
fatal: [rocky-8]: FAILED! => {
    "changed": true,
    "cmd": [
        "/usr/bin/initdb",
        "-D",
        "/var/lib/pgsql/data"
    ],
    "delta": "0:00:00.013172",
    "end": "2022-07-31 09:29:09.997343",
    "invocation": {
        "module_args": {
            "_raw_params": "/usr/bin/initdb -D /var/lib/pgsql/data",
            "_uses_shell": false,
            "argv": null,
            "chdir": null,
            "creates": null,
            "executable": null,
            "removes": null,
            "stdin": null,
            "stdin_add_newline": true,
            "strip_empty_ends": true,
            "warn": false
        }
    },
    "msg": "non-zero return code",
    "rc": 1,
    "start": "2022-07-31 09:29:09.984171",
    "stderr": "initdb: cannot be run as root\nPlease log in (using, e.g., \"su\") as the (unprivileged) user that will\nown the server process.",
    "stderr_lines": [
        "initdb: cannot be run as root",
        "Please log in (using, e.g., \"su\") as the (unprivileged) user that will",
        "own the server process."
    ],
    "stdout": "",
    "stdout_lines": []
}

pyrodie18 avatar Jul 31 '22 13:07 pyrodie18

That's strange as the task uses become to run as the user that owns the server process...... Here is the code... - name: Ensure PostgreSQL database is initialized. command: "{{ postgresql_bin_path }}/initdb -D {{ postgresql_data_dir }}" when: not pgdata_dir_version.stat.exists become: true become_user: "{{ postgresql_user }}" vars: ansible_ssh_pipelining: true

  1. If this is not the first time you are running the role, remove PG_Data directory manually.
  2. Download a fresh version of the role.
  3. You can initialize Postgresql manually (though it isn't desirable) using the command below: sudo {{postgresql_user}} initdb -D /var/lib/pgsql/data where {{postgresql_user}} is the user that owns postgresql server

mmekut avatar Aug 11 '22 13:08 mmekut

@pyrodie18 If you write become: true without defining the become_user, then the user is set to root. you cannot init a db as root so you may add become_user: "{{ postgresql_user }}" to your playbook.

fhsctv avatar Sep 20 '22 08:09 fhsctv

This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution!

Please read this blog post to see the reasons why I mark issues as stale.

stale[bot] avatar Dec 24 '22 03:12 stale[bot]

This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details.

stale[bot] avatar Feb 18 '23 06:02 stale[bot]