mysql_db: add skip_lock_tables option (#66688)

* mysql_db: add skip_lock_tables option

* add changelog fragment
This commit is contained in:
Andrew Klychkov 2020-01-22 22:19:49 +03:00 committed by Felix Fontein
parent a412e4d9fd
commit fabb2eb555
3 changed files with 17 additions and 3 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- mysql_db - add ``skip_lock_tables`` option (https://github.com/ansible/ansible/pull/66688).

View file

@ -104,6 +104,13 @@ options:
choices: [0, 1, 2]
default: 0
version_added: '2.10'
skip_lock_tables:
description:
- Skip locking tables for read. Used when I(state=dump), ignored otherwise.
required: no
type: bool
default: no
version_added: '2.10'
seealso:
- module: mysql_info
- module: mysql_variables
@ -281,7 +288,7 @@ def db_delete(cursor, db):
def db_dump(module, host, user, password, db_name, target, all_databases, port,
config_file, socket=None, ssl_cert=None, ssl_key=None, ssl_ca=None,
single_transaction=None, quick=None, ignore_tables=None, hex_blob=None,
encoding=None, force=False, master_data=0):
encoding=None, force=False, master_data=0, skip_lock_tables=False):
cmd = module.get_bin_path('mysqldump', True)
# If defined, mysqldump demands --defaults-extra-file be the first option
if config_file:
@ -305,7 +312,9 @@ def db_dump(module, host, user, password, db_name, target, all_databases, port,
if all_databases:
cmd += " --all-databases"
else:
cmd += " --databases {0} --skip-lock-tables".format(' '.join(db_name))
cmd += " --databases {0}".format(' '.join(db_name))
if skip_lock_tables:
cmd += " --skip-lock-tables"
if (encoding is not None) and (encoding != ""):
cmd += " --default-character-set=%s" % shlex_quote(encoding)
if single_transaction:
@ -449,6 +458,7 @@ def main():
hex_blob=dict(default=False, type='bool'),
force=dict(type='bool', default=False),
master_data=dict(type='int', default=0, choices=[0, 1, 2]),
skip_lock_tables=dict(type='bool', default=False),
),
supports_check_mode=True,
)
@ -486,6 +496,7 @@ def main():
hex_blob = module.params["hex_blob"]
force = module.params["force"]
master_data = module.params["master_data"]
skip_lock_tables = module.params["skip_lock_tables"]
if len(db) > 1 and state == 'import':
module.fail_json(msg="Multiple databases are not supported with state=import")
@ -552,7 +563,7 @@ def main():
login_password, db, target, all_databases,
login_port, config_file, socket, ssl_cert, ssl_key,
ssl_ca, single_transaction, quick, ignore_tables,
hex_blob, encoding, force, master_data)
hex_blob, encoding, force, master_data, skip_lock_tables)
if rc != 0:
module.fail_json(msg="%s" % stderr)
module.exit_json(changed=True, db=db_name, db_list=db, msg=stdout,

View file

@ -66,6 +66,7 @@
login_unix_socket: '{{ mysql_socket }}'
force: yes
master_data: 1
skip_lock_tables: yes
register: result
- name: assert successful completion of dump operation