postgresql_db: add dump_extra_args parameter (#66717)

* postgresql_db: add dump_extra_args parameter

* add changelog

* fix doc

* fix example
This commit is contained in:
Andrew Klychkov 2020-01-24 21:32:54 +03:00 committed by jctanner
parent 4d1e21bf18
commit 70017e2679
3 changed files with 29 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- postgresql_db - add ``dump_extra_args`` parameter (https://github.com/ansible/ansible/pull/66717).

View file

@ -107,6 +107,12 @@ options:
explicitly set this to pg_default.
type: path
version_added: '2.9'
dump_extra_args:
description:
- Provides additional arguments when I(state) is C(dump).
- Cannot be used with dump-file-format-related arguments like ``--format=d``.
type: str
version_added: '2.10'
seealso:
- name: CREATE DATABASE reference
description: Complete reference of the CREATE DATABASE command documentation.
@ -156,6 +162,13 @@ EXAMPLES = r'''
state: dump
target: /tmp/acme.sql
- name: Dump an existing database to a file excluding the test table
postgresql_db:
name: acme
state: dump
target: /tmp/acme.sql
dump_extra_args: --exclude-table=test
- name: Dump an existing database to a file (with compression)
postgresql_db:
name: acme
@ -350,6 +363,7 @@ def db_matches(cursor, db, owner, template, encoding, lc_collate, lc_ctype, conn
def db_dump(module, target, target_opts="",
db=None,
dump_extra_args=None,
user=None,
password=None,
host=None,
@ -375,6 +389,10 @@ def db_dump(module, target, target_opts="",
comp_prog_path = module.get_bin_path('xz', True)
cmd += "".join(flags)
if dump_extra_args:
cmd += " {0} ".format(dump_extra_args)
if target_opts:
cmd += " {0} ".format(target_opts)
@ -509,6 +527,7 @@ def main():
session_role=dict(type='str'),
conn_limit=dict(type='str', default=''),
tablespace=dict(type='path', default=''),
dump_extra_args=dict(type='str', default=None),
)
module = AnsibleModule(
@ -530,6 +549,7 @@ def main():
session_role = module.params["session_role"]
conn_limit = module.params['conn_limit']
tablespace = module.params['tablespace']
dump_extra_args = module.params['dump_extra_args']
raw_connection = state in ("dump", "restore")
@ -609,7 +629,11 @@ def main():
elif state in ("dump", "restore"):
method = state == "dump" and db_dump or db_restore
try:
rc, stdout, stderr, cmd = method(module, target, target_opts, db, **kw)
if state == 'dump':
rc, stdout, stderr, cmd = method(module, target, target_opts, db, dump_extra_args, **kw)
else:
rc, stdout, stderr, cmd = method(module, target, target_opts, db, **kw)
if rc != 0:
module.fail_json(msg=stderr, stdout=stdout, rc=rc, cmd=cmd)
else:

View file

@ -78,6 +78,7 @@
login_host: '{{(test_fixture == "user")|ternary("localhost", omit)}}'
login_password: '{{(test_fixture == "user")|ternary("password", omit)}}'
state: dump
dump_extra_args: --exclude-table=fake
register: result
become_user: "{{ pg_user }}"
become: yes
@ -86,6 +87,7 @@
assert:
that:
- result is changed
- result.executed_commands[0] is search("--exclude-table=fake")
- name: assert database was backed up successfully
command: file {{ db_file_name }}