def main(): module = AnsibleModule(argument_spec=dict( login_user=dict(default=None, type='str'), login_password=dict(default=None, no_log=True, type='str'), login_host=dict(default="127.0.0.1"), login_unix_socket=dict(default=None), login_port=dict(default=6032, type='int'), config_file=dict(default="", type='path'), action=dict(required=True, choices=['LOAD', 'SAVE']), config_settings=dict(required=True, choices=[ 'MYSQL USERS', 'MYSQL SERVERS', 'MYSQL QUERY RULES', 'MYSQL VARIABLES', 'ADMIN VARIABLES', 'SCHEDULER' ]), direction=dict(required=True, choices=['FROM', 'TO']), config_layer=dict(required=True, choices=['MEMORY', 'DISK', 'RUNTIME', 'CONFIG'])), supports_check_mode=True) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] action = module.params["action"] config_settings = module.params["config_settings"] direction = module.params["direction"] config_layer = module.params["config_layer"] cursor = None try: cursor, db_conn = mysql_connect(module, login_user, login_password, config_file) except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e)) result = {} manage_config_settings = \ [action, config_settings, direction, config_layer] try: result['changed'] = manage_config(manage_config_settings, cursor) except mysql_driver.Error as e: module.fail_json(msg="unable to manage config.. %s" % to_native(e)) module.exit_json(**result)
def main(): argument_spec = proxysql_common_argument_spec() argument_spec.update( action=dict(required=True, choices=['LOAD', 'SAVE']), config_settings=dict(required=True, choices=[ 'MYSQL USERS', 'MYSQL SERVERS', 'MYSQL QUERY RULES', 'MYSQL VARIABLES', 'ADMIN VARIABLES', 'SCHEDULER' ]), direction=dict(required=True, choices=['FROM', 'TO']), config_layer=dict(required=True, choices=['MEMORY', 'DISK', 'RUNTIME', 'CONFIG'])) module = AnsibleModule(supports_check_mode=True, argument_spec=argument_spec) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] action = module.params["action"] config_settings = module.params["config_settings"] direction = module.params["direction"] config_layer = module.params["config_layer"] cursor = None try: cursor, db_conn, version = mysql_connect(module, login_user, login_password, config_file) except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e)) result = {} manage_config_settings = \ [action, config_settings, direction, config_layer] try: result['changed'] = manage_config(manage_config_settings, cursor) except mysql_driver.Error as e: module.fail_json(msg="unable to manage config.. %s" % to_native(e)) module.exit_json(**result)
def main(): module = AnsibleModule(supports_check_mode=True, argument_spec=proxysql_common_argument_spec()) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn, version = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json(msg="unable to connect to ProxySQL Admin Module: %s" % to_native(e)) result = get_tables(cursor) result['version'] = version module.exit_json(**result)
def main(): module = AnsibleModule( argument_spec=dict( login_user=dict(default=None, type='str'), login_password=dict(default=None, no_log=True, type='str'), login_host=dict(default="127.0.0.1"), login_unix_socket=dict(default=None), login_port=dict(default=6032, type='int'), config_file=dict(default="", type='path'), writer_hostgroup=dict(required=True, type='int'), reader_hostgroup=dict(required=True, type='int'), comment=dict(type='str'), state=dict(default='present', choices=['present', 'absent']), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool') ), supports_check_mode=True ) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e) ) proxysql_repl_group = ProxySQLReplicationHostgroup(module) result = {} result['state'] = proxysql_repl_group.state if proxysql_repl_group.state == "present": try: if not proxysql_repl_group.check_repl_group_config(cursor, keys=True): proxysql_repl_group.create_repl_group(module.check_mode, result, cursor) else: if not proxysql_repl_group.check_repl_group_config(cursor, keys=False): proxysql_repl_group.update_repl_group(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The repl group already exists in" + " mysql_replication_hostgroups and" + " doesn't need to be updated.") result['repl_group'] = \ proxysql_repl_group.get_repl_group_config(cursor) except mysql_driver.Error as e: module.fail_json( msg="unable to modify replication hostgroup.. %s" % to_native(e) ) elif proxysql_repl_group.state == "absent": try: if proxysql_repl_group.check_repl_group_config(cursor, keys=True): proxysql_repl_group.delete_repl_group(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The repl group is already absent from the" + " mysql_replication_hostgroups memory" + " configuration") except mysql_driver.Error as e: module.fail_json( msg="unable to delete replication hostgroup.. %s" % to_native(e) ) module.exit_json(**result)
def main(): argument_spec = proxysql_common_argument_spec() argument_spec.update( hostgroup_id=dict(default=0, type='int'), hostname=dict(required=True, type='str'), port=dict(default=3306, type='int'), status=dict(choices=['ONLINE', 'OFFLINE_SOFT', 'OFFLINE_HARD']), weight=dict(type='int'), compression=dict(type='int'), max_connections=dict(type='int'), max_replication_lag=dict(type='int'), use_ssl=dict(type='bool'), max_latency_ms=dict(type='int'), comment=dict(default='', type='str'), state=dict(default='present', choices=['present', 'absent']), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool') ) module = AnsibleModule( supports_check_mode=True, argument_spec=argument_spec ) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn, version = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e) ) proxysql_server = ProxySQLServer(module) result = {} result['state'] = proxysql_server.state if proxysql_server.hostname: result['hostname'] = proxysql_server.hostname if proxysql_server.state == "present": try: if not proxysql_server.check_server_config(cursor): if not proxysql_server.check_server_config_exists(cursor): proxysql_server.create_server(module.check_mode, result, cursor) else: proxysql_server.update_server(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The server already exists in mysql_hosts" + " and doesn't need to be updated.") result['server'] = \ proxysql_server.get_server_config(cursor) except mysql_driver.Error as e: module.fail_json( msg="unable to modify server.. %s" % to_native(e) ) elif proxysql_server.state == "absent": try: if proxysql_server.check_server_config_exists(cursor): proxysql_server.delete_server(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The server is already absent from the" + " mysql_hosts memory configuration") except mysql_driver.Error as e: module.fail_json( msg="unable to remove server.. %s" % to_native(e) ) module.exit_json(**result)
def main(): module = AnsibleModule( argument_spec=dict( login_user=dict(default=None, type='str'), login_password=dict(default=None, no_log=True, type='str'), login_host=dict(default="127.0.0.1"), login_unix_socket=dict(default=None), login_port=dict(default=6032, type='int'), config_file=dict(default="", type='path'), active=dict(default=True, type='bool'), interval_ms=dict(default=10000, type='int'), filename=dict(required=True, type='str'), arg1=dict(type='str'), arg2=dict(type='str'), arg3=dict(type='str'), arg4=dict(type='str'), arg5=dict(type='str'), comment=dict(type='str'), state=dict(default='present', choices=['present', 'absent']), force_delete=dict(default=False, type='bool'), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool') ), supports_check_mode=True ) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e) ) proxysql_schedule = ProxySQLSchedule(module) result = {} result['state'] = proxysql_schedule.state result['filename'] = proxysql_schedule.filename if proxysql_schedule.state == "present": try: if proxysql_schedule.check_schedule_config(cursor) <= 0: proxysql_schedule.create_schedule(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The schedule already exists and doesn't" + " need to be updated.") result['schedules'] = \ proxysql_schedule.get_schedule_config(cursor) except mysql_driver.Error as e: module.fail_json( msg="unable to modify schedule.. %s" % to_native(e) ) elif proxysql_schedule.state == "absent": try: existing_schedules = \ proxysql_schedule.check_schedule_config(cursor) if existing_schedules > 0: if existing_schedules == 1 or proxysql_schedule.force_delete: proxysql_schedule.delete_schedule(module.check_mode, result, cursor) else: module.fail_json( msg=("Operation would delete multiple records" + " use force_delete to override this") ) else: result['changed'] = False result['msg'] = ("The schedule is already absent from the" + " memory configuration") except mysql_driver.Error as e: module.fail_json( msg="unable to remove schedule.. %s" % to_native(e) ) module.exit_json(**result)
def main(): argument_spec = proxysql_common_argument_spec() argument_spec.update(username=dict(required=True, type='str'), password=dict(no_log=True, type='str'), encrypt_password=dict(default=False, type='bool', no_log=False), encryption_method=dict( default='mysql_native_password', choices=list(encryption_method_map.keys())), active=dict(type='bool'), use_ssl=dict(type='bool'), default_hostgroup=dict(type='int'), default_schema=dict(type='str'), transaction_persistent=dict(type='bool'), fast_forward=dict(type='bool'), backend=dict(default=True, type='bool'), frontend=dict(default=True, type='bool'), max_connections=dict(type='int'), state=dict(default='present', choices=['present', 'absent']), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool')) module = AnsibleModule(supports_check_mode=True, argument_spec=argument_spec) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn, version = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e)) proxysql_user = ProxySQLUser(module) result = {} result['state'] = proxysql_user.state if proxysql_user.username: result['username'] = proxysql_user.username if proxysql_user.state == "present": try: if not proxysql_user.check_user_privs(cursor): if not proxysql_user.check_user_config_exists(cursor): proxysql_user.create_user(module.check_mode, result, cursor) else: proxysql_user.update_user(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The user already exists in mysql_users" + " and doesn't need to be updated.") result['user'] = \ proxysql_user.get_user_config(cursor) except mysql_driver.Error as e: module.fail_json(msg="unable to modify user.. %s" % to_native(e)) elif proxysql_user.state == "absent": try: if proxysql_user.check_user_config_exists(cursor): proxysql_user.delete_user(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The user is already absent from the" + " mysql_users memory configuration") except mysql_driver.Error as e: module.fail_json(msg="unable to remove user.. %s" % to_native(e)) module.exit_json(**result)
def main(): module = AnsibleModule( argument_spec=dict( login_user=dict(default=None, type='str'), login_password=dict(default=None, no_log=True, type='str'), login_host=dict(default="127.0.0.1"), login_unix_socket=dict(default=None), login_port=dict(default=6032, type='int'), config_file=dict(default="", type='path'), rule_id=dict(type='int'), active=dict(type='bool'), username=dict(type='str'), schemaname=dict(type='str'), flagIN=dict(type='int'), client_addr=dict(type='str'), proxy_addr=dict(type='str'), proxy_port=dict(type='int'), digest=dict(type='str'), match_digest=dict(type='str'), match_pattern=dict(type='str'), negate_match_pattern=dict(type='bool'), flagOUT=dict(type='int'), replace_pattern=dict(type='str'), destination_hostgroup=dict(type='int'), cache_ttl=dict(type='int'), timeout=dict(type='int'), retries=dict(type='int'), delay=dict(type='int'), mirror_flagOUT=dict(type='int'), mirror_hostgroup=dict(type='int'), error_msg=dict(type='str'), log=dict(type='bool'), apply=dict(type='bool'), comment=dict(type='str'), state=dict(default='present', choices=['present', 'absent']), force_delete=dict(default=False, type='bool'), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool') ), supports_check_mode=True ) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e) ) proxysql_query_rule = ProxyQueryRule(module) result = {} result['state'] = proxysql_query_rule.state if proxysql_query_rule.state == "present": try: if not proxysql_query_rule.check_rule_cfg_exists(cursor): if proxysql_query_rule.config_data["rule_id"] and \ proxysql_query_rule.check_rule_pk_exists(cursor): proxysql_query_rule.update_rule(module.check_mode, result, cursor) else: proxysql_query_rule.create_rule(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The rule already exists in" + " mysql_query_rules and doesn't need to be" + " updated.") result['rules'] = \ proxysql_query_rule.get_rule_config(cursor) except mysql_driver.Error as e: module.fail_json( msg="unable to modify rule.. %s" % to_native(e) ) elif proxysql_query_rule.state == "absent": try: existing_rules = proxysql_query_rule.check_rule_cfg_exists(cursor) if existing_rules > 0: if existing_rules == 1 or \ proxysql_query_rule.force_delete: proxysql_query_rule.delete_rule(module.check_mode, result, cursor) else: module.fail_json( msg=("Operation would delete multiple rules" + " use force_delete to override this") ) else: result['changed'] = False result['msg'] = ("The rule is already absent from the" + " mysql_query_rules memory configuration") except mysql_driver.Error as e: module.fail_json( msg="unable to remove rule.. %s" % to_native(e) ) module.exit_json(**result)
def main(): argument_spec = proxysql_common_argument_spec() argument_spec.update( writer_hostgroup=dict(required=True, type='int'), reader_hostgroup=dict(required=True, type='int'), check_type=dict(type='str', default='read_only', choices=['read_only', 'innodb_read_only', 'super_read_only', 'read_only|innodb_read_only', 'read_only&innodb_read_only']), comment=dict(type='str', default=''), state=dict(default='present', choices=['present', 'absent']), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool') ) module = AnsibleModule( supports_check_mode=True, argument_spec=argument_spec ) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn, version = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e) ) proxysql_repl_group = ProxySQLReplicationHostgroup(module, version) result = {} result['state'] = proxysql_repl_group.state result['changed'] = False if proxysql_repl_group.state == "present": try: if not proxysql_repl_group.check_repl_group_config(cursor, keys=True): proxysql_repl_group.create_repl_group(result, cursor) else: proxysql_repl_group.update_repl_group(result, cursor) result['repl_group'] = proxysql_repl_group.get_repl_group_config(cursor) except mysql_driver.Error as e: module.fail_json( msg="unable to modify replication hostgroup.. %s" % to_native(e) ) elif proxysql_repl_group.state == "absent": try: if proxysql_repl_group.check_repl_group_config(cursor, keys=True): proxysql_repl_group.delete_repl_group(result, cursor) else: result['changed'] = False result['msg'] = ("The repl group is already absent from the" + " mysql_replication_hostgroups memory" + " configuration") except mysql_driver.Error as e: module.fail_json( msg="unable to delete replication hostgroup.. %s" % to_native(e) ) module.exit_json(**result)
def main(): module = AnsibleModule(argument_spec=dict( login_user=dict(default=None, type='str'), login_password=dict(default=None, no_log=True, type='str'), login_host=dict(default="127.0.0.1"), login_unix_socket=dict(default=None), login_port=dict(default=6032, type='int'), config_file=dict(default="", type='path'), variable=dict(required=True, type='str'), value=dict(), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool')), supports_check_mode=True) perform_checks(module) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] variable = module.params["variable"] value = module.params["value"] save_to_disk = module.params["save_to_disk"] load_to_runtime = module.params["load_to_runtime"] cursor = None try: cursor, db_conn = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json( msg="unable to connect to ProxySQL Admin Module.. %s" % to_native(e)) result = {} if not value: try: if get_config(variable, cursor): result['changed'] = False result['msg'] = \ "Returned the variable and it's current value" result['var'] = get_config(variable, cursor) else: module.fail_json(msg="The variable \"%s\" was not found" % variable) except mysql_driver.Error as e: module.fail_json(msg="unable to get config.. %s" % to_native(e)) else: try: if get_config(variable, cursor): if not check_config(variable, value, cursor): if not module.check_mode: result['changed'] = set_config(variable, value, cursor) result['msg'] = \ "Set the variable to the supplied value" result['var'] = get_config(variable, cursor) manage_config(variable, save_to_disk, load_to_runtime, cursor, result['changed']) else: result['changed'] = True result['msg'] = ("Variable would have been set to" + " the supplied value, however" + " check_mode is enabled.") else: result['changed'] = False result['msg'] = ("The variable is already been set to" + " the supplied value") result['var'] = get_config(variable, cursor) else: module.fail_json(msg="The variable \"%s\" was not found" % variable) except mysql_driver.Error as e: module.fail_json(msg="unable to set config.. %s" % to_native(e)) module.exit_json(**result)
def main(): argument_spec = proxysql_common_argument_spec() argument_spec.update(username=dict(required=True, type='str'), schemaname=dict(required=True, type='str'), destination_hostgroup=dict(required=True, type='int'), flagIN=dict(default=0, type='int'), comment=dict(default='', type='str'), state=dict(default='present', choices=['present', 'absent']), force_delete=dict(default=False, type='bool'), save_to_disk=dict(default=True, type='bool'), load_to_runtime=dict(default=True, type='bool')) module = AnsibleModule(supports_check_mode=True, argument_spec=argument_spec) login_user = module.params["login_user"] login_password = module.params["login_password"] config_file = module.params["config_file"] cursor = None try: cursor, db_conn, version = mysql_connect(module, login_user, login_password, config_file, cursor_class='DictCursor') except mysql_driver.Error as e: module.fail_json(msg="unable to connect to ProxySQL Admin Module: %s" % to_native(e)) query_rule = ProxyQueryRuleFastRouting(module) result = {} result['state'] = query_rule.state if query_rule.state == "present": try: if not query_rule.check_rule_cfg_exists(cursor): if query_rule.config_data["username"] and query_rule.config_data["schemaname"] and \ query_rule.config_data["flagIN"] and query_rule.check_rule_pk_exists(cursor): query_rule.update_rule(module.check_mode, result, cursor) else: query_rule.create_rule(module.check_mode, result, cursor) else: result['changed'] = False result['msg'] = ("The rule already exists in " "mysql_query_rules_fast_routing " "and doesn't need to be updated.") result['rules'] = query_rule.get_rule_config(cursor) except mysql_driver.Error as e: module.fail_json(msg="unable to modify rule: %s" % to_native(e)) elif query_rule.state == "absent": try: existing_rules = query_rule.check_rule_cfg_exists(cursor) if existing_rules > 0: if existing_rules == 1 or query_rule.force_delete: query_rule.delete_rule(module.check_mode, result, cursor) else: module.fail_json(msg=( "Operation would delete multiple rules use force_delete to override this." )) else: result['changed'] = False result['msg'] = ("The rule is already absent from the " "mysql_query_rules_fast_routing memory " "configuration") except mysql_driver.Error as e: module.fail_json(msg="unable to remove rule: %s" % to_native(e)) module.exit_json(**result)