ANXS / postgresql

Fairly full featured Ansible role for Postgresql.
http://anxs.io/
MIT License
849 stars 573 forks source link

error installing PG 11 on Fedora 30 #434

Closed vladp closed 4 years ago

vladp commented 5 years ago

Cannot figure out what I am doing wrong, appreciate, in advance, any help/pointers.

Setup:

target host Running Fedora 30 (within Vagrant: config.vm.box = "fedora/30-cloud-base" ) ANXS from git repo (not from galaxy) ansible 2.7 python is python3 not using mitogen

I checked the roles, code and in configure.yml it sets the become_user to postgres_service_user , which is itself set to postgres_admin_user..

that seems to be correct. I do not know how to debug if become is indeed executed. But the code for ansible_os_family=="Redhat" seems to be doing the right thing.

fatal: [pg2nd__atlanta__dbhost]: FAILED! => {"changed": true, "cmd": ["/usr/pgsql-11/bin/initdb", "-D", "/var/lib/pgsq
l/11/main", "--locale=en_US.UTF-8", "--encoding=UTF-8"], "delta": "0:00:00.086695", "end": "2019-05-19 00:09:05.976242", "msg": "non-zero return code", "rc": 1, "start": "2019-05-19 00:09:05.889547", "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": []}

Role parameters


---
# pg database servers
- hosts: pg_db
  become: yes
  roles:
      - role: ANXS.postgresql
        no_log: False  # added to get  better output, can be removed

        postgresql_version: 11
        postgresql_encoding: "UTF-8"
        postgresql_locale: "en_US.UTF-8"
        postgresql_ctype: "en_US.UTF-8"

        postgresql_admin_user: "postgres"
        postgresql_default_auth_method: "peer"
        postgresql_pg_hba_default:
           # .. deleted for brevity
        # end of hba stuff

        #start user
        postgresql_users:
          - name: x
            pass: x
            encrypted: no       # denotes if the password is already encrypted.

        postgresql_user_privileges:
          - name: x             # user name
            db: mydb_common             # database
            priv: "ALL"                 # privilege string format: example: INSERT,UPDATE/table:SELECT/anothertable:ALL
            role_attr_flags: "CREATEDB" # role attribute flags
        #end user
      postgresql_service_enabled: true # should the service be enabled, default is true

        postgresql_ext_install_contrib: yes
        postgresql_cluster_name: "main"
        postgresql_cluster_reset: false

        postgresql_port: "{{pgsrv_port}}"  # custom host var that  knows the expected port for pg
        postgresql_listen_addresses: "*"
        postgresql_databases:
          - name: mydb_common
       postgresql_database_extentions:
          - db: mydb_common
            extensions:
              - ltree
              - uuid-ossp
              - pgcrypto 
              - intarray 

        # List of schemas to be created (optional)
        postgresql_schemas:
          - database: mydb_common        # database name
            schema: mydbschema_public               # schema name
            owner: x
            state: present
gclough commented 5 years ago

@nysan , do you have Fedora experience?

vladp commented 5 years ago

is there a working task/playbook that somebody could share where this roles on any of the redhat-family systems (redhat, fedora, centos)

I am not able to resolve the above error despite my best effort

vladp commented 5 years ago

despite my best effort, this is a problem with that I cannot seem to resolve. I suspect this will be a problem on RedHat derived setups (fedora, redhat, centos). Reason why it does not show up when this role is run on Debian-derived distros -- is because, for those a different cluster initialization method is used.

I also do not think that the problem is with this role, instead this looks like a problem with Postgres's initdb. This role correctly sets the 'become' user to be postgres administrator (which by default is postgres).

Even if ansible logs in as 'postgres' user, initdb still thinks that the user trying to run initdb is root

I even wrote a simple task with 'command' module to just call initdb -- and it fails with the same error message: initdb: cannot be run as root

I can avoid this error if I tell this role to not initialize the cluster directory (and instead, I would have to login to each PG host and do it manually).

So to avoid the error do: postgresql_cluster_reset: false

When setting variables for the ANSX.postgresql role

jtognazzi commented 5 years ago

I just tested on my fedora 30 with the test playbook And it worked... For info, the role version is v1.11.1

vladp commented 4 years ago

Just a quick update. Again , I do not think there is any problem with this role, so will close the issue.

I think I am running into an ansible issue

https://github.com/ansible/ansible/issues/38129

Because I include role that underneath uses this role, via include_role. And that way of including roles, underneath somehow makes ansible ignore the
become: yes become_user: 'postgres'

in configure.yml (lines around 107) that are executed for Redhat systems only.

So the reasons why others are not running into this is because most are probably not including roles with include_role

The error still on CentOS8


ans/roles/ANXS.postgresql/tasks/configure.yml:102
fatal: [primarynode__pgdb]: FAILED! => {"changed": true, "cmd": ["/usr/pgsql-12/bin/initdb", "-D", "/var/lib/pgsql/12/main", "--locale=en_US.UTF-8", "--encoding=UTF-8"], "delta": "0:00:00.066498", "end": "2020-05-30 01:49:55.765010", "msg": "non-zero return code", "rc": 1, "start": "2020-05-30 01:49:55.698512", "stderr": "initdb: error: 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: error: 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": []}

The target host was initialized by using Centos8 distro https://app.vagrantup.com/generic/boxes/centos8 version 3.0.6

The postgres distro was installed manually using:


dnf install https://download.postgresql.org/pub/repos/yum/reporpms/EL-8-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf -qy module disable postgresql
dnf install   postgresql12  postgresql12-server

(these are steps prescribed in https://www.postgresql.org/download/linux/redhat/ )

vladp commented 4 years ago

this issue is not due the code in this role