Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User creation and DB creation in the same run not working #152

Open
johnkeates opened this issue Jun 11, 2017 · 4 comments
Open

User creation and DB creation in the same run not working #152

johnkeates opened this issue Jun 11, 2017 · 4 comments

Comments

@johnkeates
Copy link
Contributor

johnkeates commented Jun 11, 2017

Creating a user and assigning a database (or the other way around) doesn't work properly. Probably because users are fetched and cached?


      ID: postgres_user-provisioner_local
Function: postgres_user.present
    Name: provisioner_local
  Result: True
 Comment: The user provisioner_local has been created
 Started: 15:13:29.747481
Duration: 519.459 ms
 Changes:   
          ----------
          provisioner_local:
              Present

      ID: postgres_database-provisioner_local
Function: postgres_database.present
    Name: provisioner_local
  Result: False
 Comment: An exception occurred in this state: Traceback (most recent call last):
            File "/usr/lib/python2.7/dist-packages/salt/state.py", line 1746, in call
              **cdata['kwargs'])
            File "/usr/lib/python2.7/dist-packages/salt/loader.py", line 1704, in wrapper
              return f(*args, **kwargs)
            File "/usr/lib/python2.7/dist-packages/salt/states/postgres_database.py", line 98, in present
              dbs = __salt__['postgres.db_list'](**db_args)
            File "/usr/lib/python2.7/dist-packages/salt/modules/postgres.py", line 461, in db_list
              password=password)
            File "/usr/lib/python2.7/dist-packages/salt/modules/postgres.py", line 417, in psql_query
              password=password)
            File "/usr/lib/python2.7/dist-packages/salt/modules/postgres.py", line 364, in _psql_prepare_and_run
              rcmd, runas=runas, password=password, host=host, port=port, user=user)
            File "/usr/lib/python2.7/dist-packages/salt/modules/postgres.py", line 181, in _run_psql
              ret = __salt__['cmd.run_all'](cmd, python_shell=False, **kwargs)
            File "/usr/lib/python2.7/dist-packages/salt/modules/cmdmod.py", line 1662, in run_all
              **kwargs)
            File "/usr/lib/python2.7/dist-packages/salt/modules/cmdmod.py", line 394, in _run
              'User \'{0}\' is not available'.format(runas)
          CommandExecutionError: User 'provisioner_local' is not available
 Started: 15:13:30.268091
Duration: 13.714 ms
 Changes:   `

Pillar:
`

postgres:
  #pg_hba.conf: salt://postgres/pg_hba.conf
  conf_dir: /etc/postgresql/9.4/main
  lookup:
    pkg: 'postgresql-9.4'
    pkg_client: 'postgresql-client-9.4'
    pkg_dev: 'postgresql-server-dev-9.4'
    pkg_contrib: 'postgresql-contrib-9.4'
    pg_hba: '/etc/postgresql/9.4/main/pg_hba.conf'
  version: 9.4

  users:
      provisioner_local:
        password: 'dfsjkle45980dfgkjl'
        createdb: False

  acls:
    - ['host', 'provisioner_local', 'provisioner_local', '0.0.0.0/0', 'md5']


  databases:
    provisioner_local:
      owner: 'provisioner_local'
      user: 'provisioner_local'
      template: 'template0'
      lc_ctype: 'C.UTF-8'
      lc_collate: 'C.UTF-8'
   
  postgresconf: |
    listen_addresses = '0.0.0.0'

`

@johnkeates
Copy link
Contributor Author

Well, it basically doesn't work no matter what actually. Manually creating the database and then running state.apply isn't working either.

@dahrens
Copy link

dahrens commented Aug 16, 2017

I can confirm this. I've updated the formula today from upstream and receive the same error. For me it looks like the postgres.database.present gets fired and tries to execute the command as the user that is passed in as owner. The user is not a user in the system, but just a database role.

@dahrens
Copy link

dahrens commented Aug 16, 2017

Oh, directly after commenting I decided to read the documentation linked above.

@johnkeates you should not pass the argument user as this forces the behavior I described above. Only pass owner to ensure the owner gets set correctly. user forces salt to execute the command as this unix user, which is not present.

@noelmcloughlin
Copy link
Member

noelmcloughlin commented Sep 14, 2017

Might be duplicated in #158

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants