diff options
author | Brian Coca <bcoca@ansible.com> | 2015-02-03 07:34:16 -0500 |
---|---|---|
committer | Brian Coca <bcoca@ansible.com> | 2015-02-03 07:34:16 -0500 |
commit | 6a3bba3ecc184a50539044e26e1324a8b2adfd99 (patch) | |
tree | 2967a13895796b7411d658bed72ab1bc74126e19 /database/mysql | |
parent | a951bf63e7cdabe171584f663500c1eb88748706 (diff) | |
parent | d611f86e5b3644421b2f24eb1b5af2c6eb7be61d (diff) | |
download | ansible-modules-extras-6a3bba3ecc184a50539044e26e1324a8b2adfd99.tar.gz |
Merge pull request #21 from Jmainguy/mysql_replication_login_port
Adds login_port feature, similiar to how mysql_db.py works
Diffstat (limited to 'database/mysql')
-rw-r--r-- | database/mysql/mysql_replication.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/database/mysql/mysql_replication.py b/database/mysql/mysql_replication.py index 70e226a6..07d09602 100644 --- a/database/mysql/mysql_replication.py +++ b/database/mysql/mysql_replication.py @@ -54,6 +54,12 @@ options: description: - mysql host to connect required: False + login_port: + description: + - Port of the MySQL server. Requires login_host be defined as other then localhost if login_port is used + required: False + default: 3306 + version_added: "1.9" login_unix_socket: description: - unix socket to connect mysql server @@ -115,6 +121,9 @@ EXAMPLES = ''' # Change master to master server 192.168.1.1 and use binary log 'mysql-bin.000009' with position 4578 - mysql_replication: mode=changemaster master_host=192.168.1.1 master_log_file=mysql-bin.000009 master_log_pos=4578 + +# Check slave status using port 3308 +- mysql_replication: mode=getslave login_host=ansible.example.com login_port=3308 ''' import ConfigParser @@ -230,6 +239,7 @@ def main(): login_user=dict(default=None), login_password=dict(default=None), login_host=dict(default="localhost"), + login_port=dict(default="3306"), login_unix_socket=dict(default=None), mode=dict(default="getslave", choices=["getmaster", "getslave", "changemaster", "stopslave", "startslave"]), master_host=dict(default=None), @@ -252,6 +262,7 @@ def main(): user = module.params["login_user"] password = module.params["login_password"] host = module.params["login_host"] + port = module.params["login_port"] mode = module.params["mode"] master_host = module.params["master_host"] master_user = module.params["master_user"] @@ -293,8 +304,10 @@ def main(): try: if module.params["login_unix_socket"]: db_connection = MySQLdb.connect(host=module.params["login_host"], unix_socket=module.params["login_unix_socket"], user=login_user, passwd=login_password) + elif module.params["login_port"] != "3306" and module.params["login_host"] == "localhost": + module.fail_json(msg="login_host is required when login_port is defined, login_host cannot be localhost when login_port is defined") else: - db_connection = MySQLdb.connect(host=module.params["login_host"], user=login_user, passwd=login_password) + db_connection = MySQLdb.connect(host=module.params["login_host"], port=int(module.params["login_port"]), user=login_user, passwd=login_password) except Exception, e: module.fail_json(msg="unable to connect to database, check login_user and login_password are correct or ~/.my.cnf has the credentials") try: |