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_db dump does not fail on FATAL error when using compression #39412

Closed
d-fence opened this issue Apr 27, 2018 · 3 comments
Closed

postgresql_db dump does not fail on FATAL error when using compression #39412

d-fence opened this issue Apr 27, 2018 · 3 comments
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. postgresql PostgreSQL community support:community This issue/PR relates to code supported by the Ansible community.

Comments

@d-fence
Copy link

d-fence commented Apr 27, 2018

ISSUE TYPE
  • Bug Report
COMPONENT NAME

postgresql_db

ANSIBLE VERSION
ansible 2.5.1
  config file = /home/xxx/ansible/ansible.cfg
  configured module search path = [u'/home/xxx/ansible/library']
  ansible python module location = /home/xxx/.virtualenvs/ansiblexxx/local/lib/python2.7/site-packages/ansible
  executable location = /home/xxx/.virtualenvs/ansiblexxx/bin/ansible
  python version = 2.7.14 (default, Sep 23 2017, 22:06:14) [GCC 7.2.0]
CONFIGURATION

ANSIBLE_NOCOWS(/home/xxx/ansible/ansible.cfg) = True
ANSIBLE_PIPELINING(/home/xxx/ansible/ansible.cfg) = True
DEFAULT_FORKS(/home/xxx/ansible/ansible.cfg) = 50
DEFAULT_HOST_LIST(/home/xxx/ansible/ansible.cfg) = [u'/home/xxx/ansible/inventories']
DEFAULT_MODULE_PATH(/home/xxx/ansible/ansible.cfg) = [u'/home/xxx/ansible/library']
DEFAULT_MODULE_UTILS_PATH(/home/xxx/ansible/ansible.cfg) = [u'/home/xxx/ansible/module_utils']
DEFAULT_ROLES_PATH(/home/xxx/ansible/ansible.cfg) = [u'/home/xxx/ansible/roles']
INVENTORY_IGNORE_EXTS(/home/xxx/ansible/ansible.cfg) = ['~', '.orig', '.bak', '.ini', '.cfg', '.retry', '.pyc', '.pyo', '.cache']

OS / ENVIRONMENT

N/A
postgresql 9.5

SUMMARY

When using the dump state to dump a database, with compression like .gz, if an error occurs, it's not propagated to ansible. It seems that rc contains only the return code of the gzip program.

STEPS TO REPRODUCE
---
- name: Backup xxx DB
  hosts: xxx_hosts
  tasks:
  - name: Backup xxx database
    become: True
    become_user: postgres
    postgresql_db:
      name: non_existsing_db
      state: dump
      target: /tmp/db.sql.gz
EXPECTED RESULTS

The playbook should fail and stop right after the failed dump

ACTUAL RESULTS
changed: [xxx.yyy.com] => {"changed": true, "cmd": "/usr/bin/pg_dump non_existsing_db --port=5432 --username=postgres|/bin/gzip > /tmp/db.sql.gz", "msg": "", "rc": 0, "stderr": "pg_dump: [archiver (db)] connection to database \"non_existing_db\" failed: FATAL:  database \"non_existing_db\" does not exist\n", "stderr_lines": ["pg_dump: [archiver (db)] connection to database \"non_existing_db\" failed: FATAL:  database \"non_existing_db\" does not exist"]}
@ansibot
Copy link
Contributor

ansibot commented Apr 27, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Apr 27, 2018

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:community This issue/PR relates to code supported by the Ansible community. labels Apr 27, 2018
@Akasurde Akasurde removed the needs_triage Needs a first human triage before being processed. label Apr 27, 2018
ansibot pushed a commit that referenced this issue Nov 26, 2018
* postgresql_db dump does not fail on FATAL error when using compression
@Akasurde
Copy link
Member

Closing this issue as PR #39483 is merged. If issue persists, please feel free to re-open.

mjmayer pushed a commit to mjmayer/ansible that referenced this issue Nov 30, 2018
* postgresql_db dump does not fail on FATAL error when using compression
@dagwieers dagwieers added the postgresql PostgreSQL community label Jan 28, 2019
Glandos added a commit to Glandos/ansible that referenced this issue Mar 5, 2019
'dump' and 'restore' state only need pg_dump and pg_restore. These tools
don't use psycopg2 so this change tries to avoid the use of it in these
cases.

The db_exists test was replaced with an error detection when piping to
compression program, using a FIFO file. This effectively reverts ansible#39483,
that was a fix for ansible#39412.
gundalow pushed a commit that referenced this issue Mar 11, 2019
* Remove dependency to psycopg2 with dump/restore

'dump' and 'restore' state only need pg_dump and pg_restore. These tools
don't use psycopg2 so this change tries to avoid the use of it in these
cases.

The db_exists test was replaced with an error detection when piping to
compression program, using a FIFO file. This effectively reverts #39483,
that was a fix for #39412.

* Fix typo

* Add changelog fragment

* Add note for dump and restore not requiring psycopg2

* Fix YAML syntax

* Update lib/ansible/modules/database/postgresql/postgresql_db.py

Co-Authored-By: Glandos <bugs-github@antipoul.fr>
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 bug This issue/PR relates to a bug. module This issue/PR relates to a module. postgresql PostgreSQL community support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

No branches or pull requests

4 participants