From 5308fbdeaceea60be5e85354cf2fe63fd7779ce3 Mon Sep 17 00:00:00 2001 From: Alex Vandiver Date: Thu, 21 Sep 2023 21:40:15 -0400 Subject: [PATCH] puppet: Add postgresql-client depenencies to monitoring. The `unless` step errors out if /usr/bin/psql does not exist at first evaluation time -- protect that with a `test -f` check, and protect the actual `createuser` with a dependency on `postgresql-client`. To work around `Zulip::Safepackage` not actually being safe to instantiate more than once, we move the instantiation of `Package[postgresql-client]` into a class which can be safely included one or more times. --- puppet/zulip/manifests/app_frontend_base.pp | 6 ++---- puppet/zulip/manifests/postgresql_client.pp | 8 ++++++++ puppet/zulip_ops/manifests/prometheus/postgresql.pp | 4 +++- 3 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 puppet/zulip/manifests/postgresql_client.pp diff --git a/puppet/zulip/manifests/app_frontend_base.pp b/puppet/zulip/manifests/app_frontend_base.pp index 122dc8572c..20176d8237 100644 --- a/puppet/zulip/manifests/app_frontend_base.pp +++ b/puppet/zulip/manifests/app_frontend_base.pp @@ -10,10 +10,8 @@ class zulip::app_frontend_base { if $::os['family'] == 'Debian' { # Upgrade and other tooling wants to be able to get a database # shell. This is not necessary on CentOS because the PostgreSQL - # package already includes the client. This may get us a more - # recent client than the database server is configured to be, - # ($zulip::postgresql_common::version), but they're compatible. - zulip::safepackage { 'postgresql-client': ensure => installed } + # package already includes the client. + include zulip::postgresql_client } # For Slack import zulip::safepackage { 'unzip': ensure => installed } diff --git a/puppet/zulip/manifests/postgresql_client.pp b/puppet/zulip/manifests/postgresql_client.pp new file mode 100644 index 0000000000..cffcde3c84 --- /dev/null +++ b/puppet/zulip/manifests/postgresql_client.pp @@ -0,0 +1,8 @@ +class zulip::postgresql_client { + # This may get us a more recent client than the database server is + # configured to be, ($zulip::postgresql_common::version), but + # they're compatible. + package { 'postgresql-client': + ensure => installed, + } +} diff --git a/puppet/zulip_ops/manifests/prometheus/postgresql.pp b/puppet/zulip_ops/manifests/prometheus/postgresql.pp index e41b4a7e10..09e0ca4c0c 100644 --- a/puppet/zulip_ops/manifests/prometheus/postgresql.pp +++ b/puppet/zulip_ops/manifests/prometheus/postgresql.pp @@ -47,9 +47,11 @@ class zulip_ops::prometheus::postgresql { require => Exec['compile postgres_exporter'], } + include zulip::postgresql_client exec { 'create prometheus postgres user': + require => Package['postgresql-client'], command => '/usr/bin/createuser -g pg_monitor prometheus', - unless => '/usr/bin/psql -tAc "select usename from pg_user" | /bin/grep -xq prometheus', + unless => 'test -f /usr/bin/psql && /usr/bin/psql -tAc "select usename from pg_user" | /bin/grep -xq prometheus', user => 'postgres', }