Skip to content

Commit

Permalink
Add missing options to CHANGE MASTER TO
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge-Rodriguez committed Jan 22, 2023
1 parent c242584 commit 6a8026e
Showing 1 changed file with 200 additions and 2 deletions.
202 changes: 200 additions & 2 deletions plugins/modules/mysql_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
author:
- Balazs Pocze (@banyek)
- Andrew Klychkov (@Andersson007)
- Jorge Rodriguez (@Jorge-Rodriguez)
options:
mode:
description:
Expand All @@ -42,6 +43,12 @@
- resetreplica
- resetreplicaall
default: getreplica
primary_bind:
description:
- Same as the C(MASTER_BIND) mysql variable.
type: str
aliases: [master_bind]
version_added: 3.6.0
primary_host:
description:
- Same as the C(MASTER_HOST) mysql variable.
Expand All @@ -62,11 +69,23 @@
- Same as the C(MASTER_PORT) mysql variable.
type: int
aliases: [master_port]
primary_heartbeat_period:
description:
- Same as the C(MASTER_HEARTBEAT_PERIOD) mysql variable.
type: int
aliases: [master_heartbeat_period]
version_added: 3.6.0
primary_connect_retry:
description:
- Same as the C(MASTER_CONNECT_RETRY) mysql variable.
type: int
aliases: [master_connect_retry]
primary_retry_count:
description:
- Same as the C(MASTER_RETRY_COUNT) mysql variable.
type: int
aliases: [master_retry_count]
version_added: 3.6.0
primary_log_file:
description:
- Same as the C(MASTER_LOG_FILE) mysql variable.
Expand Down Expand Up @@ -116,6 +135,22 @@
L(MySQL encrypted replication documentation,https://dev.mysql.com/doc/refman/8.0/en/replication-solutions-encrypted-connections.html).
type: str
aliases: [master_ssl_cert]
primary_ssl_crl:
description:
- Same as the C(MASTER_SSL_CRL) mysql variable.
- For details, refer to
L(MySQL encrypted replication documentation,https://dev.mysql.com/doc/refman/8.0/en/replication-solutions-encrypted-connections.html).
type: str
aliases: [master_ssl_crl]
version_added: 3.6.0
primary_ssl_crlpath:
description:
- Same as the C(MASTER_SSL_CRLPATH) mysql variable.
- For details, refer to
L(MySQL encrypted replication documentation,https://dev.mysql.com/doc/refman/8.0/en/replication-solutions-encrypted-connections.html).
type: str
aliases: [master_ssl_crlpath]
version_added: 3.6.0
primary_ssl_key:
description:
- Same as the C(MASTER_SSL_KEY) mysql variable.
Expand All @@ -133,17 +168,42 @@
aliases: [master_ssl_cipher]
primary_ssl_verify_server_cert:
description:
- Same as mysql variable.
- Same as the C(MASTER_SSL_VERIFY_SERVER_CERT) mysql variable.
type: bool
default: false
version_added: '3.5.0'
aliases: [master_ssl_verify_server_cert]
version_added: 3.5.0
primary_tls_version:
description:
- Same as the C(MASTER_TLS_VERSION) mysql variable.
type: str
aliases: [master_tls_version]
version_added: 3.6.0
primary_auto_position:
description:
- Whether the host uses GTID based replication or not.
- Same as the C(MASTER_AUTO_POSITION) mysql variable.
type: bool
default: false
aliases: [master_auto_position]
ignore_server_ids:
description:
- List of server IDs whose events are ignored.
type: list
elements: str
version_added: 3.6.0
do_domain_ids:
description:
- Same as MariaDB variable.
type: list
elements: str
version_added: 3.6.0
ignore_domain_ids:
description:
- Same as MariaDB variable.
type: list
elements: str
version_added: 3.6.0
primary_use_gtid:
description:
- Configures the replica to use the MariaDB Global Transaction ID.
Expand All @@ -164,6 +224,64 @@
type: int
version_added: '0.1.0'
aliases: [master_delay]
privilege_checks_user:
description:
- Same as mysql variable.
choices: [account]
type: str
version_added: 3.6.0
require_row_format:
description:
- Same as mysql variable.
type: bool
version_added: 3.6.0
require_table_primary_key_check:
description:
- Same as mysql variable.
choices: [stream, on, off]
type: str
version_added: 3.6.0
source_connection_auto_failover:
description:
- Same as mysql variable.
type: bool
version_added: 3.6.0
primary_compression_algorithms:
description:
- Same as the C(MASTER_COMPRESSION_ALGORITHM) mysql variable.
type: str
aliases: [master_compression_algorithm]
version_added: 3.6.0
primary_zstd_compression_level:
description:
- Same as the C(MASTER_ZSTD_COMPRESSION_LEVEL) mysql variable.
choices: [1-22]
type: int
aliases: [master_zstd_compression_level]
version_added: 3.6.0
primary_tls_ciphersuites:
description:
- Same as the C(MASTER_TLS_CIPHERSUITES) mysql variable.
type: str
aliases: [master_tls_ciphersuites]
version_added: 3.6.0
primary_public_key_path:
description:
- Same as the C(MASTER_PUBLIC_KEY_PATH) mysql variable.
type: str
aliases: [master_public_key_path]
version_added: 3.6.0
get_primary_public_key:
description:
- Same as the C(GET_MASTER_PUBLIC_KEY) mysql variable.
type: bool
aliases: [get_master_public_key]
version_added: 3.6.0
network_namespace:
description:
- Same as mysql variable.
type: str
version_added: 3.6.0
connection_name:
description:
- Name of the primary connection.
Expand Down Expand Up @@ -449,11 +567,14 @@ def main():
'resetreplica',
'resetreplicaall']),
primary_auto_position=dict(type='bool', default=False, aliases=['master_auto_position']),
primary_bind=dict(type='str', aliases=['master_bind']),
primary_host=dict(type='str', aliases=['master_host']),
primary_user=dict(type='str', aliases=['master_user']),
primary_password=dict(type='str', no_log=True, aliases=['master_password']),
primary_port=dict(type='int', aliases=['master_port']),
primary_heartbeat_period=dict(type='int', aliases=['master_heartbeat_period']),
primary_connect_retry=dict(type='int', aliases=['master_connect_retry']),
primary_retry_count=dict(type='int', aliases=['master_retry_count']),
primary_log_file=dict(type='str', aliases=['master_log_file']),
primary_log_pos=dict(type='int', aliases=['master_log_pos']),
relay_log_file=dict(type='str'),
Expand All @@ -462,13 +583,30 @@ def main():
primary_ssl_ca=dict(type='str', aliases=['master_ssl_ca']),
primary_ssl_capath=dict(type='str', aliases=['master_ssl_capath']),
primary_ssl_cert=dict(type='str', aliases=['master_ssl_cert']),
primary_ssl_crl=dict(type='str', aliases=['master_ssl_crl']),
primary_ssl_crlpath=dict(type='str', aliases=['master_ssl_crlpath']),
primary_ssl_key=dict(type='str', no_log=False, aliases=['master_ssl_key']),
primary_ssl_cipher=dict(type='str', aliases=['master_ssl_cipher']),
primary_ssl_verify_server_cert=dict(type='bool', default=False, aliases=['master_ssl_verify_server_cert']),
primary_tls_version=dict(type='str', aliases=['master_tls_version']),
primary_compression_algorithms=dict(type='str', aliases=['master_compression_algorithms']),
primary_zstd_compression_level=dict(type='int', choices=list(range(1, 23)), aliases=['master_zstd_compression_level']),
primary_tls_ciphersuites=dict(type='str', aliases=['master_tls_ciphersuites']),
primary_public_key_path=dict(type='str', aliases=['master_public_key_path']),
get_primary_public_key=dict(type='bool', default=False, aliases=['get_master_public_key']),
primary_ssl_verify_server_cert=dict(type='bool', default=False),
primary_use_gtid=dict(type='str', choices=[
'current_pos', 'replica_pos', 'disabled'], aliases=['master_use_gtid']),
ignore_server_ids=dict(type='list'),
do_domain_ids=dict(type='list'),
ignore_domain_ids=dict(type='list'),
primary_delay=dict(type='int', aliases=['master_delay']),
connection_name=dict(type='str'),
privilege_checks_user=dict(type='str', choices=['account']),
require_row_format=dict(type='bool', default=False),
require_table_primary_key_check=dict(type='str', choices=['stream', 'on', 'off']),
source_connection_auto_failover=dict(type='bool', default=False),
network_namespace=dict(type='str'),
channel=dict(type='str'),
fail_on_error=dict(type='bool', default=False),
)
Expand All @@ -479,11 +617,14 @@ def main():
],
)
mode = module.params["mode"]
primary_bind = module.params["primary_bind"]
primary_host = module.params["primary_host"]
primary_user = module.params["primary_user"]
primary_password = module.params["primary_password"]
primary_port = module.params["primary_port"]
primary_heartbeat_period = module.params["primary_heartbeat_period"]
primary_connect_retry = module.params["primary_connect_retry"]
primary_retry_count = module.params["primary_retry_count"]
primary_log_file = module.params["primary_log_file"]
primary_log_pos = module.params["primary_log_pos"]
relay_log_file = module.params["relay_log_file"]
Expand All @@ -492,10 +633,27 @@ def main():
primary_ssl_ca = module.params["primary_ssl_ca"]
primary_ssl_capath = module.params["primary_ssl_capath"]
primary_ssl_cert = module.params["primary_ssl_cert"]
primary_ssl_crl = module.params["priamry_ssl_crl"]
primary_ssl_crlpath = module.params["priamry_ssl_crlpath"]
primary_ssl_key = module.params["primary_ssl_key"]
primary_ssl_cipher = module.params["primary_ssl_cipher"]
primary_ssl_verify_server_cert = module.params["primary_ssl_verify_server_cert"]
primary_tls_version = module.params["primary_tls_version"]
primary_compression_algorithms = module.params["primary_compression_algorithms"]
primary_zstd_compression_level = module.params["primary_zstd_compression_level"]
primary_tls_ciphersuites = module.params["mprimarytls_ciphersuites"]
primary_public_key_path = module.params["primary_public_key_path"]
get_primary_public_key = module.params["get_primary_public_key"]
primary_ssl_verify_server_cert = module.params["primary_ssl_verify_server_cert"]
primary_auto_position = module.params["primary_auto_position"]
ignore_server_ids = module.params["ignore_server_ids"]
do_domain_ids = module.params["do_domain_ids"]
ignore_domain_ids = module.params["ignore_domain_ids"]
privilege_checks_user = module.params["privilege_checks_user"]
require_row_format = module.params["require_row_format"]
require_table_primary_key_check = module.params["require_table_primary_key_check"]
source_connection_auto_failover = module.params["source_connection_auto_failover"]
network_namespace = module.params["network_namespace"]
ssl_cert = module.params["client_cert"]
ssl_key = module.params["client_key"]
ssl_ca = module.params["ca_cert"]
Expand Down Expand Up @@ -568,6 +726,8 @@ def main():
elif mode == 'changeprimary':
chm = []
result = {}
if primary_bind is not None:
chm.append("MASTER_BIND='%s'" % primary_bind)
if primary_host is not None:
chm.append("MASTER_HOST='%s'" % primary_host)
if primary_user is not None:
Expand All @@ -576,8 +736,12 @@ def main():
chm.append("MASTER_PASSWORD='%s'" % primary_password)
if primary_port is not None:
chm.append("MASTER_PORT=%s" % primary_port)
if primary_heartbeat_period is not None:
chm.append("MASTER_HEARTBEAT_PERIOD='%s'" % primary_heartbeat_period)
if primary_connect_retry is not None:
chm.append("MASTER_CONNECT_RETRY=%s" % primary_connect_retry)
if primary_retry_count is not None:
chm.append("MASTER_RETRY_COUNT='%s'" % primary_retry_count)
if primary_log_file is not None:
chm.append("MASTER_LOG_FILE='%s'" % primary_log_file)
if primary_log_pos is not None:
Expand All @@ -599,16 +763,50 @@ def main():
chm.append("MASTER_SSL_CAPATH='%s'" % primary_ssl_capath)
if primary_ssl_cert is not None:
chm.append("MASTER_SSL_CERT='%s'" % primary_ssl_cert)
if primary_ssl_crl is not None:
chm.append("MASTER_SSL_CRL='%s'" % primary_ssl_crl)
if primary_ssl_crlpath is not None:
chm.append("MASTER_SSL_CRLPATH='%s'" % primary_ssl_crlpath)
if primary_ssl_key is not None:
chm.append("MASTER_SSL_KEY='%s'" % primary_ssl_key)
if primary_ssl_cipher is not None:
chm.append("MASTER_SSL_CIPHER='%s'" % primary_ssl_cipher)
if primary_ssl_verify_server_cert:
chm.append("MASTER_SSL_VERIFY_SERVER_CERT=1")
if primary_tls_version is not None:
chm.append("MASTER_TLS_VERSION='%s'" % primary_tls_version)
if primary_compression_algorithms is not None:
chm.append("MASTER_COMPRESSION_ALGORITHMS='%s'" % primary_compression_algorithms)
if primary_zstd_compression_level is not None:
chm.append("MASTER_ZSTD_COMPRESSION_LEVEL='%s'" % primary_zstd_compression_level)
if primary_tls_ciphersuites is not None:
chm.append("MASTER_TLS_CIPHERSUITES='%s'" % primary_tls_ciphersuites)
if primary_public_key_path is not None:
chm.append("MASTER_PUBLIC_KEY_PATH='%s'" % primary_public_key_path)
if get_primary_public_key:
chm.append("GET_MASTER_PUBLIC_KEY=1")
if primary_ssl_verify_server_cert:
chm.append("SOURCE_SSL_VERIFY_SERVER_CERT=1")
if primary_auto_position:
chm.append("MASTER_AUTO_POSITION=1")
if primary_use_gtid is not None:
chm.append("MASTER_USE_GTID=%s" % primary_use_gtid)
if ignore_server_ids:
chm.append("IGNORE_SERVER_IDS='%s'" % ','.join(ignore_server_ids))
if do_domain_ids:
chm.append("DO_DOMAIN_IDS='%s'" % ','.join(do_domain_ids))
if ignore_domain_ids:
chm.append("IGNORE_DOMAIN_IDS='%s'" % ','.join(ignore_domain_ids))
if privilege_checks_user is not None:
chm.append("PRIVILEGE_CHECKS_USER='%s'" % privilege_checks_user)
if require_row_format:
chm.append("REQUIRE_ROW_FORMAT=1")
if require_table_primary_key_check is not None:
chm.append("REQUIRE_TABLE_PRIMARY_KEY_CHECK='%s'" % require_table_primary_key_check)
if source_connection_auto_failover:
chm.append("SOURCE_CONNECTION_AUTO_FAILOVER=1")
if network_namespace is not None:
chm.append("NETWORK_NAMESPACE='%s'" % network_namespace)
try:
changeprimary(cursor, chm, connection_name, channel)
except mysql_driver.Warning as e:
Expand Down

0 comments on commit 6a8026e

Please sign in to comment.