Page MenuHomePhabricator

puppetdb postgress server: fix dependcey loop
Closed, ResolvedPublic

Description

in profile::puppetdb::database we have the following dependency: Postgresql::User<| |> -> Postgresql::Db<| |>. however this causes an unrecoverable loop where the users cant be created as the user resource also tries to grant permissions to a specific database. however the db dosn;t exists leading to the following puppet output

Notice: /Stage[main]/Puppet_compiler/Exec[install compiler]: Triggered 'refresh' from 1 event
Notice: /Stage[main]/Profile::Puppetdb::Database/Postgresql::User[puppetdb_ro@localhost]/Postgresql::Db_grant[grant access to puppetdb_ro@localhost on puppetdb]/Exec[db_grant: exec table grants grant access to puppetdb_ro@localhost on puppetdb]/returns: psql: FATAL:  database "puppetdb" does not exist
Error: '/usr/bin/psql --tuples-only --no-align  -c 'GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO puppetdb_ro' puppetdb' returned 2 instead of one of [0]
Error: /Stage[main]/Profile::Puppetdb::Database/Postgresql::User[puppetdb_ro@localhost]/Postgresql::Db_grant[grant access to puppetdb_ro@localhost on puppetdb]/Exec[db_grant: exec table grants grant access to puppetdb_ro@localhost on puppetdb]/returns: change from 'notrun' to ['0'] failed: '/usr/bin/psql --tuples-only --no-align  -c 'GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO puppetdb_ro' puppetdb' returned 2 instead of one of [0] (corrective)
Notice: /Stage[main]/Profile::Puppetdb::Database/Postgresql::User[puppetdb_ro@localhost]/Postgresql::Db_grant[grant access to puppetdb_ro@localhost on puppetdb]/Exec[db_grant: exec sequence grants grant access to puppetdb_ro@localhost on puppetdb]/returns: psql: FATAL:  database "puppetdb" does not exist
Error: '/usr/bin/psql --tuples-only --no-align  -c 'GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO puppetdb_ro' puppetdb' returned 2 instead of one of [0]
Error: /Stage[main]/Profile::Puppetdb::Database/Postgresql::User[puppetdb_ro@localhost]/Postgresql::Db_grant[grant access to puppetdb_ro@localhost on puppetdb]/Exec[db_grant: exec sequence grants grant access to puppetdb_ro@localhost on puppetdb]/returns: change from 'notrun' to ['0'] failed: '/usr/bin/psql --tuples-only --no-align  -c 'GRANT USAGE ON ALL SEQUENCES IN SCHEMA "public" TO puppetdb_ro' puppetdb' returned 2 instead of one of [0] (corrective)
Notice: /Stage[main]/Profile::Puppetdb::Database/Postgresql::User[puppetdb_ro@localhost]/Postgresql::Db_grant[grant access to puppetdb_ro@localhost on puppetdb]/Exec[db_grant: exec function grants grant access to puppetdb_ro@localhost on puppetdb]/returns: psql: FATAL:  database "puppetdb" does not exist
Error: '/usr/bin/psql --tuples-only --no-align  -c 'GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "public" TO puppetdb_ro' puppetdb' returned 2 instead of one of [0]
Error: /Stage[main]/Profile::Puppetdb::Database/Postgresql::User[puppetdb_ro@localhost]/Postgresql::Db_grant[grant access to puppetdb_ro@localhost on puppetdb]/Exec[db_grant: exec function grants grant access to puppetdb_ro@localhost on puppetdb]/returns: change from 'notrun' to ['0'] failed: '/usr/bin/psql --tuples-only --no-align  -c 'GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA "public" TO puppetdb_ro' puppetdb' returned 2 instead of one of [0] (corrective)

which is cause by the following error

 sudo -u postgres /usr/bin/psql --tuples-only --no-align  -c 'GRANT SELECT ON ALL TABLES IN SCHEMA "public" TO puppetdb_ro' puppetdb
psql: FATAL:  database "puppetdb" does not exist

As a quick fix i manully ran

$ sudo systemctl restart postgres
$ sudo -u postgres /usr/bin/createdb --owner='puppetdb' puppetdb

Related Objects

Event Timeline

jbond triaged this task as Medium priority.Nov 26 2021, 4:23 PM
jbond created this task.
Restricted Application added a subscriber: Aklapper. · View Herald Transcript

Change 800031 had a related patch set uploaded (by Filippo Giunchedi; author: Filippo Giunchedi):

[operations/puppet@production] puppetdb: create dbs before grants

https://gerrit.wikimedia.org/r/800031

With filippos latest patch the only outstanding error is

May 27 08:10:10 filippo-pdb-01 puppet-agent[17242]: (/Stage[main]/Postgresql::Server/Exec[pgreload]/returns) pg_ctl: directory "/srv/postgres/11/main" is not a database cluster directory
May 27 08:10:10 filippo-pdb-01 puppet-agent[17242]: (/Stage[main]/Postgresql::Server/Exec[pgreload]) Failed to call refresh: '/usr/bin/pg_ctlcluster 11 main reload' returned 1 instead of one of [0]

see P28628

Change 800031 merged by Filippo Giunchedi:

[operations/puppet@production] puppetdb: create dbs before grants

https://gerrit.wikimedia.org/r/800031

jbond added a subscriber: hnowlan.

@hnowlan fyi there may be some of this going on im not sure

jhathaway added a subscriber: fgiunchedi.

In my testing this has been resolved by @fgiunchedi's patch