Salt Wants To Create postgres User That Exists
A possible issue with 2014.1.1-1 on CentOS 6.5 using the EPEL RPMs.
I have a postgres user that was created just fine in the 0.17 series and before. I updated this server to 2014.1.1 and now Salt wants to create the postgres user that already exists:
----------
ID: postgresql
Function: postgres_user.present
Name: samhain
Result: None
Comment: User samhain is set to be created
Which of course if I try it without test=True fails:
ID: postgresql
Function: postgres_user.present
Name: samhain
Result: False
Comment: Failed to create user samhain
Changes:
Some debug with test=True enabled:
[INFO ] Executing state postgres_user.present for samhain
[INFO ] Executing command '/usr/bin/psql --no-align --no-readline --dbname
postgres -c \'SELECT setting FROM pg_catalog.pg_settings WHERE name =
\'"\'"\'server_version\'"\'"\'\' -t' as user 'postgres' in directory
'/var/lib/pgsql'
[INFO ] stdout: 8.4.20
[INFO ] Executing command '/usr/bin/psql --no-align --no-readline --dbname
postgres -v datestyle=ISO,MDY -c \'COPY (SELECT pg_roles.rolname as
"name",pg_roles.rolsuper as "superuser", pg_roles.rolinherit as "inherits
privileges", pg_roles.rolcreaterole as "can create roles",
pg_roles.rolcreatedb as "can create databases", pg_roles.rolcatupdate as "can
update system catalogs", pg_roles.rolcanlogin as "can login", pg_roles.NULL as
"replication", pg_roles.rolconnlimit as "connections",
pg_roles.rolvaliduntil::timestamp(0) as "expiry time", pg_roles.rolconfig as
"defaults variables", COALESCE(pg_shadow.passwd, pg_authid.rolpassword) as
"password" FROM pg_roles LEFT JOIN pg_authid ON pg_roles.oid = pg_authid.oid
LEFT JOIN pg_shadow ON pg_roles.oid = pg_shadow.usesysid) TO STDOUT WITH CSV
HEADER\'' as user 'postgres' in directory '/var/lib/pgsql'
[ERROR ] Command '/usr/bin/psql --no-align --no-readline --dbname postgres -
v datestyle=ISO,MDY -c \'COPY (SELECT pg_roles.rolname as
"name",pg_roles.rolsuper as "superuser", pg_roles.rolinherit as "inherits
privileges", pg_roles.rolcreaterole as "can create roles",
pg_roles.rolcreatedb as "can create databases", pg_roles.rolcatupdate as "can
update system catalogs", pg_roles.rolcanlogin as "can login", pg_roles.NULL as
"replication", pg_roles.rolconnlimit as "connections",
pg_roles.rolvaliduntil::timestamp(0) as "expiry time", pg_roles.rolconfig as
"defaults variables", COALESCE(pg_shadow.passwd, pg_authid.rolpassword) as
"password" FROM pg_roles LEFT JOIN pg_authid ON pg_roles.oid = pg_authid.oid
LEFT JOIN pg_shadow ON pg_roles.oid = pg_shadow.usesysid) TO STDOUT WITH CSV
HEADER\'' failed with return code: 1
[ERROR ] stderr: ERROR: column pg_roles.null does not exist
LINE 1: ...m catalogs", pg_roles.rolcanlogin as "can login", pg_roles.N...
^
[INFO ] User samhain is set to be created
[INFO ] Completed state [samhain] at time 16:48:30.441627
Some debug when I don't run test=True, it does see that the user exists.
[INFO ] Executing command '/usr/bin/psql --no-align --no-readline --dbname
postgres -c \'CREATE ROLE "samhain" WITH INHERIT NOCREATEDB NOSUPERUSER LOGIN
ENCRYPTED PASSWORD \'"\'"\'<SNIP>\'"\'"\'\'' as user 'postgres' in directory
'/var/lib/pgsql'
[ERROR ] Command '/usr/bin/psql --no-align --no-readline --dbname postgres -
c \'CREATE ROLE "samhain" WITH INHERIT NOCREATEDB NOSUPERUSER LOGIN ENCRYPTED
PASSWORD \'"\'"\'<SNIP>\'"\'"\'\'' failed with return code: 1
[ERROR ] stderr: ERROR: role "samhain" already exists
[ERROR ] Failed to create user samhain
Thanks.
Thanks for letting us know. This should be fairly straightforward to fix.
@kiorky You may want to be aware of this. I know that #9831 touched a lot of this code.
So I spent some time debugging this and was unable to reproduce.
Steps
- create superuser "someuser" on postgres 9.2 server (centos 6.5)
createuser -s -h localhost -U testuser -W -P otheruser - run highstate
postgres-user:
postgres_user.present:
- name: otheruser
- superuser: True
- password: 'otheruser'
- db_user: testuser
- db_password: test
- db_host: postgres
- db_port: 5432
[root@salt-master-test postgres]# sudo salt '*' state.highstate
salt-postgres-test:
----------
ID: postgres-user
Function: postgres_user.present
Name: otheruser
Result: True
Comment: User otheruser is already present
Changes:
Summary
------------
Succeeded: 1
Failed: 0
------------
Total: 1
@linuxlewis Was this against develop or a release version?
Let me finish being pulled 10 different directions at work and I'll post my formulas.
@cachedout I was using the latest stable in yum.
@linuxlewis Could you post a salt --versions-report please? I assume that's 2014.1.1 but would like to be certain.
@cachedout
[root@salt-master-test ~]# salt --versions-report
Salt: 2014.1.0
Python: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
Jinja2: 2.2.1
M2Crypto: 0.20.2
msgpack-python: 0.1.13
msgpack-pure: Not Installed
pycrypto: 2.0.1
PyYAML: 3.10
PyZMQ: 2.2.0.1
ZMQ: 3.2.4
looks like I wasn't on 2014.1.1
I was using these http://docs.saltstack.com/en/latest/topics/installation/rhel.html#installing-stable-release
I'll get the right version installed and try again
Same result
[root@salt-master-test postgres]# sudo salt '*' state.highstate
postgres-test:
----------
ID: postgres-user
Function: postgres_user.present
Name: otheruser
Result: True
Comment: User otheruser is already present
Changes:
Summary
------------
Succeeded: 1
Failed: 0
------------
Total: 1
[root@salt-master-test postgres]# salt --versions-report
Salt: 2014.1.1
Python: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
Jinja2: 2.2.1
M2Crypto: 0.20.2
msgpack-python: 0.1.13
msgpack-pure: Not Installed
pycrypto: 2.0.1
PyYAML: 3.10
PyZMQ: 2.2.0.1
ZMQ: 3.2.4
[root@salt-master-test postgres]#
Versions Report:
Salt: 2014.1.1
Python: 2.6.6 (r266:84292, Jan 22 2014, 09:42:36)
Jinja2: unknown
M2Crypto: 0.20.2
msgpack-python: 0.1.13
msgpack-pure: Not Installed
pycrypto: 2.0.1
PyYAML: 3.10
PyZMQ: 2.2.0.1
ZMQ: 3.2.4
Formula for the whole thing:
postgresql:
cmd:
- run
- name: "/etc/init.d/postgresql initdb"
- unless: "[ -e /var/lib/pgsql/data/postgresql.conf ]"
- require:
- pkg: postgresql
postgres_user:
- present
- name: samhain
- createdb: False
- createuser: False
- superuser: False
- password: {{ salt['pillar.get']('yule:pgpwd') }}
- runas: "postgres"
- require:
- service: postgresql
postgres_database:
- present
- name: mydatabasename
- runas: "postgres"
- require:
- service: postgresql
pkg:
- installed
- name: postgresql-server
service:
- running
- enable: True
- require:
- cmd: postgresql
- watch:
- file: /var/lib/pgsql/data/pg_hba.conf
Thanks, @knine I am able to reproduce. Based on the logs it looks like the query to look for the existing user is failing. Which is why the script is always trying to create a user.
Looks like it was already fixed by this commit: https://github.com/saltstack/salt/commit/1a4ca7ed6dcf8734af2ddfa91a1fc6746bffaa93
Not sure how this gets fixed from here cc @cachedout
@linuxlewis Any chance you can test it with the changes in 1a4ca7e ? Looks like only two lines so it should be easy to modify and test. If that does fix it, then we'll see about getting that into an upcoming minor release. If not, we'll have to figure out what's going on and fix it.
Fixed in #10491
@linuxlewis @cachedout Was this pushed to any of the bugfix releases? I can confirm that this issue still exists in 2014.1.7-3.el6. Thanks!
It does not appear to have been cherry-picked, so no, it's not in a current release of salt. I'm wary of trying to cherry-pick it at this point, as there seems to be some extensive history and multiple sets of changes involved.
We plan to release 2014.7.0rc1 next week, so at this point I'm leaning towards holding off on trying to backport this fix.
Sound good, just wanted to FYI in case it was thought to be and was not working. Thanks!
@knine To verify, would you mind testing on the develop or 2014.7 branches?
I'll have to set something up to test it (I should have that already, I'm a slacker), I won't get to it immediately, but I'll let you know.
Just a +1 that I'm also being affected by this.