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

Postgresql_user not indempotent fails when re-run playbook as database is deleted. #459

Open
mdiogene opened this issue Apr 29, 2023 · 2 comments

Comments

@mdiogene
Copy link

SUMMARY

The module postgresql_user is notindepotent, it fails when the playbook is re-executed.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

postgresql_user

ANSIBLE VERSION
ansible [core 2.14.1]
COLLECTION VERSION
# /usr/local/lib/python3.9/dist-packages/ansible_collections
Collection           Version
-------------------- -------
community.postgresql 2.3.1  

# /usr/lib/python3/dist-packages/ansible_collections
Collection           Version
-------------------- -------
community.postgresql 1.1.1
CONFIGURATION
CONFIG_FILE() = None
OS / ENVIRONMENT

CentOS 7

STEPS TO REPRODUCE
- name: "Delete user {{ item.name }}"
  postgresql_user:
    db: "{{ CURRENT_USER_REMOVE.name }}"
    name: "{{ item.name }}"
    priv: "{{ item.priv }}"
    state: absent
  with_items:
    - "{{ CURRENT_USER_REMOVE.user }}"
  tags: delete_user
EXPECTED RESULTS

The playbook must not failed when re-run (after database deletion)

ACTUAL RESULTS

failed: [sv-pdb] (item={'name': 'antho', 'priv': 'ALL'}) => {"ansible_loop_var": "item", "changed": false, "item": {"name": "antho", "priv": "ALL"}, "msg": "unable to connect to database: la connexion au serveur sur le socket « /var/run/postgresql/.s.PGSQL.5432 » a échoué : FATAL: la base de données « HISTOIRE » n'existe pas\n"}


@mdiogene mdiogene changed the title Postgresql_user/postgresql_db not indempotent fails when re-run playbook as database is deleted. Postgresql_user not indempotent fails when re-run playbook as database is deleted. Apr 29, 2023
@mdiogene
Copy link
Author

You must use failed_when: false if you don't want it fail.
But if a use still exits and database is deleted the user cannot be deleted.

@Andersson007
Copy link
Collaborator

@mdiogene hello, thanks for reporting the issue!
The module documentation for the db option says:

Name of database to connect to and where user's permissions will be granted.

If the database doesn't exist, the failure seems expected as the module just can't connect to a non-existing database.
In this case, you could try to connect to the postgres db when the state is absent. Would this work for you?

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

2 participants