example42/puppet-postgresql

Puppet 3.2.3 on Ubuntu 12.04 - Postgresql::Hbaconcat wipes pg_hba.conf blank

Closed this issue · 3 comments

I purged all postgresql packages from the server to ensure I wasn't seeing some artifact of my previous attempts, then added a simple

class {'puppetdb': 
    db_type => 'postgresql',
  }

to my node and ran puppet on the puppetdb server.
Here's my output:

# puppet agent -tv 
Info: Retrieving plugin
Info: Loading facts in /var/lib/puppet/lib/facter/last_run.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppi_projects.rb
Info: Caching catalog for puppetclient
Info: Applying configuration version '1376274329'
Notice: /Stage[main]/Postgresql/Package[postgresql]/ensure: ensure changed 'purged' to 'present'
Notice: /Stage[main]/Postgresql/File[postgresql.conf]/mode: mode changed '0644' to '0600'
Info: /Stage[main]/Postgresql/File[postgresql.conf]: Scheduling refresh of Service[postgresql]
Notice: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/File[/etc/postgresql/9.1/main/pg_hba.conf]/content: 
--- /etc/postgresql/9.1/main/pg_hba.conf        2013-08-12 02:27:03.487796138 +0000
+++ /tmp/puppet-file20130812-10176-mfqpae       2013-08-12 02:27:07.479796139 +0000
@@ -1,99 +0,0 @@
-# PostgreSQL Client Authentication Configuration File
-# ===================================================
-#
-# Refer to the "Client Authentication" section in the PostgreSQL
-# documentation for a complete description of this file.  A short
-# synopsis follows.
-#
-# This file controls: which hosts are allowed to connect, how clients
-# are authenticated, which PostgreSQL user names they can use, which
-# databases they can access.  Records take one of these forms:
-#
-# local      DATABASE  USER  METHOD  [OPTIONS]
-# host       DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
-# hostssl    DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
-# hostnossl  DATABASE  USER  ADDRESS  METHOD  [OPTIONS]
-#
-# (The uppercase items must be replaced by actual values.)
-#
-# The first field is the connection type: "local" is a Unix-domain
-# socket, "host" is either a plain or SSL-encrypted TCP/IP socket,
-# "hostssl" is an SSL-encrypted TCP/IP socket, and "hostnossl" is a
-# plain TCP/IP socket.
-#
-# DATABASE can be "all", "sameuser", "samerole", "replication", a
-# database name, or a comma-separated list thereof. The "all"
-# keyword does not match "replication". Access to replication
-# must be enabled in a separate record (see example below).
-#
-# USER can be "all", a user name, a group name prefixed with "+", or a
-# comma-separated list thereof.  In both the DATABASE and USER fields
-# you can also write a file name prefixed with "@" to include names
-# from a separate file.
-#
-# ADDRESS specifies the set of hosts the record matches.  It can be a
-# host name, or it is made up of an IP address and a CIDR mask that is
-# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
-# specifies the number of significant bits in the mask.  A host name
-# that starts with a dot (.) matches a suffix of the actual host name.
-# Alternatively, you can write an IP address and netmask in separate
-# columns to specify the set of hosts.  Instead of a CIDR-address, you
-# can write "samehost" to match any of the server's own IP addresses,
-# or "samenet" to match any address in any subnet that the server is
-# directly connected to.
-#
-# METHOD can be "trust", "reject", "md5", "password", "gss", "sspi",
-# "krb5", "ident", "peer", "pam", "ldap", "radius" or "cert".  Note that
-# "password" sends passwords in clear text; "md5" is preferred since
-# it sends encrypted passwords.
-#
-# OPTIONS are a set of options for the authentication in the format
-# NAME=VALUE.  The available options depend on the different
-# authentication methods -- refer to the "Client Authentication"
-# section in the documentation for a list of which options are
-# available for which authentication methods.
-#
-# Database and user names containing spaces, commas, quotes and other
-# special characters must be quoted.  Quoting one of the keywords
-# "all", "sameuser", "samerole" or "replication" makes the name lose
-# its special character, and just match a database or username with
-# that name.
-#
-# This file is read on server startup and when the postmaster receives
-# a SIGHUP signal.  If you edit the file on a running system, you have
-# to SIGHUP the postmaster for the changes to take effect.  You can
-# use "pg_ctl reload" to do that.
-
-# Put your actual configuration here
-# ----------------------------------
-#
-# If you want to allow non-local connections, you need to add more
-# "host" records.  In that case you will also need to make PostgreSQL
-# listen on a non-local interface via the listen_addresses
-# configuration parameter, or via the -i or -h command line switches.
-
-
-
-
-# DO NOT DISABLE!
-# If you change this first entry you will need to make sure that the
-# database superuser can access the database using some other method.
-# Noninteractive access to all databases is required during automatic
-# maintenance (custom daily cronjobs, replication, and similar tasks).
-#
-# Database administrative login by Unix domain socket
-local   all             postgres                                peer
-
-# TYPE  DATABASE        USER            ADDRESS                 METHOD
-
-# "local" is for Unix domain socket connections only
-local   all             all                                     peer
-# IPv4 local connections:
-host    all             all             127.0.0.1/32            md5
-# IPv6 local connections:
-host    all             all             ::1/128                 md5
-# Allow replication connections from localhost, by a user with the
-# replication privilege.
-#local   replication     postgres                                peer
-#host    replication     postgres        127.0.0.1/32            md5
-#host    replication     postgres        ::1/128                 md5

Info: FileBucket got a duplicate file {md5}7694a77a71d01d43944f0ec2aa3fb165
Info: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/File[/etc/postgresql/9.1/main/pg_hba.conf]: Filebucketed /etc/postgresql/9.1/main/pg_hba.conf to puppet with sum 7694a77a71d01d43944f0ec2aa3fb165
Notice: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/File[/etc/postgresql/9.1/main/pg_hba.conf]/content: content changed '{md5}7694a77a71d01d43944f0ec2aa3fb165' to '{md5}d41d8cd98f00b204e9800998ecf8427e'
Notice: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/File[/etc/postgresql/9.1/main/pg_hba.conf]/mode: mode changed '0640' to '0600'
Notice: /Stage[main]/Postgresql/Service[postgresql]: Triggered 'refresh' from 1 events
Notice: /Stage[main]/Puppetdb::Postgresql/Postgresql::Dbcreate[puppetdb]/Exec[role_puppetdb]/returns: psql: FATAL:  no pg_hba.conf entry for host "[local]", user "postgres", database "postgres", SSL off
Error: echo "create role puppetdb nosuperuser nocreatedb nocreaterole noinherit nologin ; alter role puppetdb nosuperuser nocreatedb nocreaterole noinherit login encrypted password '75712058861'; grant puppetdb to puppetdb; create database puppetdb with OWNER=puppetdb TEMPLATE=template1 ENCODING='SQL_ASCII' LC_COLLATE='C' LC_CTYPE='C';" | /usr/bin/psql returned 2 instead of one of [0]
Error: /Stage[main]/Puppetdb::Postgresql/Postgresql::Dbcreate[puppetdb]/Exec[role_puppetdb]/returns: change from notrun to 0 failed: echo "create role puppetdb nosuperuser nocreatedb nocreaterole noinherit nologin ; alter role puppetdb nosuperuser nocreatedb nocreaterole noinherit login encrypted password '75712058861'; grant puppetdb to puppetdb; create database puppetdb with OWNER=puppetdb TEMPLATE=template1 ENCODING='SQL_ASCII' LC_COLLATE='C' LC_CTYPE='C';" | /usr/bin/psql returned 2 instead of one of [0]
Notice: /Stage[main]/Puppetdb/Exec[/usr/sbin/puppetdb-ssl-setup]/returns: executed successfully
Notice: Finished catalog run in 26.31 seconds

As mentioned in the subject, I'm on Ubuntu 12.04 LTS, running the latest puppet 3.2.3 (from puppetlabs' repo) on both master and this client.

I've looked at the postgresql::hbaconcat class, and it looks fine to me.
The concat module I'm using is the latest from puppetlabs, do you think that's the issue? It looked more up-to-date than the e42 copy.
I'll grab the e42 concat module and try it, to eliminate this as the cause..

OK, so switching to e42 concat gave me:

# puppet agent -tv 
Info: Retrieving plugin
Notice: /File[/var/lib/puppet/lib/facter/concat_basedir.rb]/content: 
--- /var/lib/puppet/lib/facter/concat_basedir.rb        2013-08-09 06:49:53.915796139 +0000
+++ /tmp/puppet-file20130812-12169-3396yg       2013-08-12 02:49:02.507796138 +0000
@@ -1,9 +1,3 @@
-# == Fact: concat_basedir
-#
-# A custom fact that sets the default location for fragments
-#
-# "${::vardir}/concat/"
-#
 Facter.add("concat_basedir") do
     setcode do
         File.join(Puppet[:vardir],"concat")

Notice: /File[/var/lib/puppet/lib/facter/concat_basedir.rb]/content: content changed '{md5}e152593fafe27ef305fc473929c62ca6' to '{md5}f2e991697602ffb3e80e0cc9efa37f3a'
Info: Loading facts in /var/lib/puppet/lib/facter/last_run.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppi_projects.rb
Info: Caching catalog for puppetclient
Info: Applying configuration version '1376275741'
Notice: /Stage[main]/Concat::Setup/File[/var/lib/puppet/concat/bin/concatfragments.sh]/content: 
--- /var/lib/puppet/concat/bin/concatfragments.sh       2013-08-12 01:24:16.271796135 +0000
+++ /tmp/puppet-file20130812-12169-12liyjw      2013-08-12 02:49:08.127796139 +0000
@@ -26,6 +26,7 @@
 #       is generated by puppet
 #  -f   Enables the creation of empty output files when no fragments are found
 #  -n  Sort the output numerically rather than the default alpha sort
+#  -g  Do NOT use the GNU entensions to find, xargs and sort; might cause problems on suitably funky filenames
 #
 # the command: 
 #
@@ -43,7 +44,10 @@
 TEST=""
 FORCE=""
 WARN=""
-SORTARG=""
+SORT1="-z"
+SORT2=""
+FINDARG="-print0"
+XARGSARG="-0"

 PATH=/sbin:/usr/sbin:/bin:/usr/bin

@@ -51,19 +55,22 @@
 ## http://nexenta.org/projects/site/wiki/Personalities
 unset SUN_PERSONALITY

-while getopts "o:s:d:tnw:f" options; do
+while getopts "o:s:d:tnw:fg" options; do
        case $options in
                o ) OUTFILE=$OPTARG;;
                d ) WORKDIR=$OPTARG;;
-               n ) SORTARG="-n";;
+               n ) SORT2="-n";;
                w ) WARNMSG="$OPTARG";;
                f ) FORCE="true";;
                t ) TEST="true";;
+               g ) FINDARG="" ; XARGSARG="" ; SORT1="" ;;
                * ) echo "Specify output file with -o and fragments directory with -d"
                    exit 1;;
        esac
 done

+SORTARG="$SORT1 $SORT2"
+
 # do we have -o?
 if [ x${OUTFILE} = "x" ]; then
        echo "Please specify an output file with -o"
@@ -105,21 +112,14 @@

 cd ${WORKDIR}

-if [ "x${WARNMSG}" = "x" ]; then
+if [ x${WARNMSG} = "x" ]; then
        : > "fragments.concat"
 else
        printf '%s\n' "$WARNMSG" > "fragments.concat"
 fi

 # find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir
-IFS_BACKUP=$IFS
-IFS='
-'
-for fragfile in `find fragments/ -type f -follow | LANG=C sort ${SORTARG}`
-do
-    cat $fragfile >> concat.fragment
-done
-IFS=$IFS_BACKUP
+find fragments/ -type f -follow $FINDARG |sort ${SORTARG}|xargs $XARGSARG cat >>"fragments.concat"

 if [ x${TEST} = "x" ]; then
        # This is a real run, copy the file to outfile

Info: FileBucket adding {md5}b03aef3be08f0dcd5e7723fa70b6ddf4
Info: /Stage[main]/Concat::Setup/File[/var/lib/puppet/concat/bin/concatfragments.sh]: Filebucketed /var/lib/puppet/concat/bin/concatfragments.sh to puppet with sum b03aef3be08f0dcd5e7723fa70b6ddf4
Notice: /Stage[main]/Concat::Setup/File[/var/lib/puppet/concat/bin/concatfragments.sh]/content: content changed '{md5}b03aef3be08f0dcd5e7723fa70b6ddf4' to '{md5}c3971a69d71bff0a945ad3b61edff32f'
Notice: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/Exec[concat_/etc/postgresql/9.1/main/pg_hba.conf]/returns: executed successfully
Notice: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/File[/etc/postgresql/9.1/main/pg_hba.conf]/content: 
--- /etc/postgresql/9.1/main/pg_hba.conf        2013-08-12 02:27:07.567796138 +0000
+++ /tmp/puppet-file20130812-12169-1mmtr7o      2013-08-12 02:49:09.091796139 +0000
@@ -0,0 +1,13 @@
+# File Managed by Puppet
+
+# Database administrative login by Unix domain socket
+local   all             postgres                                ident
+host   puppetdb        puppetdb        127.0.0.1/32    md5   
+
+# "local" is for Unix domain socket connections only
+local   all         all                               ident
+# IPv4 local connections:
+host    all         all         127.0.0.1/32          ident
+# IPv6 local connections:
+host    all         all         ::1/128               ident
+

Info: FileBucket adding {md5}d41d8cd98f00b204e9800998ecf8427e
Info: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/File[/etc/postgresql/9.1/main/pg_hba.conf]: Filebucketed /etc/postgresql/9.1/main/pg_hba.conf to puppet with sum d41d8cd98f00b204e9800998ecf8427e
Notice: /Stage[main]/Postgresql::Hbaconcat/Concat[/etc/postgresql/9.1/main/pg_hba.conf]/File[/etc/postgresql/9.1/main/pg_hba.conf]/content: content changed '{md5}d41d8cd98f00b204e9800998ecf8427e' to '{md5}9782ffafd5819afe2f93f3a474fe13eb'
Notice: /Stage[main]/Puppetdb::Postgresql/Postgresql::Dbcreate[puppetdb]/Exec[role_puppetdb]/returns: psql: FATAL:  no pg_hba.conf entry for host "[local]", user "postgres", database "postgres", SSL off
Error: echo "create role puppetdb nosuperuser nocreatedb nocreaterole noinherit nologin ; alter role puppetdb nosuperuser nocreatedb nocreaterole noinherit login encrypted password '75712058861'; grant puppetdb to puppetdb; create database puppetdb with OWNER=puppetdb TEMPLATE=template1 ENCODING='SQL_ASCII' LC_COLLATE='C' LC_CTYPE='C';" | /usr/bin/psql returned 2 instead of one of [0]
Error: /Stage[main]/Puppetdb::Postgresql/Postgresql::Dbcreate[puppetdb]/Exec[role_puppetdb]/returns: change from notrun to 0 failed: echo "create role puppetdb nosuperuser nocreatedb nocreaterole noinherit nologin ; alter role puppetdb nosuperuser nocreatedb nocreaterole noinherit login encrypted password '75712058861'; grant puppetdb to puppetdb; create database puppetdb with OWNER=puppetdb TEMPLATE=template1 ENCODING='SQL_ASCII' LC_COLLATE='C' LC_CTYPE='C';" | /usr/bin/psql returned 2 instead of one of [0]
Notice: /Stage[main]/Puppetdb/Exec[/usr/sbin/puppetdb-ssl-setup]/returns: executed successfully
Notice: Finished catalog run in 7.16 seconds

Then I reloaded postgres to pick up the file change, and voila:

# /etc/init.d/postgresql reload
 * Reloading PostgreSQL 9.1 database server
# puppet agent -tv 
Info: Retrieving plugin
Info: Loading facts in /var/lib/puppet/lib/facter/last_run.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppet_vardir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/root_home.rb
Info: Loading facts in /var/lib/puppet/lib/facter/facter_dot_d.rb
Info: Loading facts in /var/lib/puppet/lib/facter/pe_version.rb
Info: Loading facts in /var/lib/puppet/lib/facter/concat_basedir.rb
Info: Loading facts in /var/lib/puppet/lib/facter/puppi_projects.rb
Info: Caching catalog for puppetclient
Info: Applying configuration version '1376275741'
Notice: /Stage[main]/Puppetdb::Postgresql/Postgresql::Dbcreate[puppetdb]/Exec[role_puppetdb]/returns: executed successfully
Notice: /Stage[main]/Puppetdb/Exec[/usr/sbin/puppetdb-ssl-setup]/returns: executed successfully
Notice: Finished catalog run in 6.62 seconds

So, as the issue appears to be with concat, not this postgresql, I'll close this issue and open a new one in concat for us to update that module with the latest from upstream (and test to make sure it still works!!) :)

EDIT: It appears that the e42 concat module doesn't have 'issues' turned on, so I can't log anything against it..

Now you should be able to add issues to the concat module.
Ideally we should use directly the upstream version, but given its core importance for some modules, maybe is safer to keep a local, tested, version.
Anyway if you discover something let us know..