mysql_replication: add resetmaster choice to mode param
diff --git a/changelogs/fragments/63321-mysql_replication_add_resetmaster_to_mode.yml b/changelogs/fragments/63321-mysql_replication_add_resetmaster_to_mode.yml
new file mode 100644
index 00000000000000..c4c112a1448045
--- /dev/null
+++ b/changelogs/fragments/63321-mysql_replication_add_resetmaster_to_mode.yml
@@ -0,0 +1,2 @@
+minor_changes:
+- mysql_replication - add support of ``resetmaster`` choice to ``mode`` parameter (https://github.com/ansible/ansible/issues/42870).
diff --git a/lib/ansible/modules/database/mysql/mysql_replication.py b/lib/ansible/modules/database/mysql/mysql_replication.py
index 364b3a2b43df40..9c261a435083a6 100644
--- a/lib/ansible/modules/database/mysql/mysql_replication.py
+++ b/lib/ansible/modules/database/mysql/mysql_replication.py
@@ -34,6 +34,7 @@
       C(getslave) (SHOW SLAVE STATUS),
       C(startslave) (START SLAVE),
       C(stopslave) (STOP SLAVE),
+      C(resetmaster) (RESET MASTER) - supported from Ansible 2.10,
       C(resetslave) (RESET SLAVE),
       C(resetslaveall) (RESET SLAVE ALL).
     type: str
@@ -43,6 +44,7 @@
     - getslave
     - startslave
     - stopslave
+    - resetmaster
     - resetslave
     - resetslaveall
     default: getslave
@@ -200,6 +202,12 @@
   mysql_replication:
     mode: stopslave
     channel: master-1
+
+- name: >
+    Run RESET MASTER command which will delete all existing binary log files
+    and reset the binary log index file on the master
+  mysql_replication:
+    mode: resetmaster
 '''
 
 RETURN = r'''
@@ -295,6 +303,17 @@ def reset_slave_all(cursor, connection_name='', channel=''):
     return reset
 
 
+def reset_master(cursor):
+    query = 'RESET MASTER'
+    try:
+        executed_queries.append(query)
+        cursor.execute(query)
+        reset = True
+    except Exception:
+        reset = False
+    return reset
+
+
 def start_slave(cursor, connection_name='', channel=''):
     if connection_name:
         query = "START SLAVE '%s'" % connection_name
@@ -335,7 +354,8 @@ def main():
             login_port=dict(type='int', default=3306),
             login_unix_socket=dict(type='str'),
             mode=dict(type='str', default='getslave', choices=[
-                'getmaster', 'getslave', 'changemaster', 'stopslave', 'startslave', 'resetslave', 'resetslaveall']),
+                'getmaster', 'getslave', 'changemaster', 'stopslave',
+                'startslave', 'resetmaster', 'resetslave', 'resetslaveall']),
             master_auto_position=dict(type='bool', default=False),
             master_host=dict(type='str'),
             master_user=dict(type='str'),
@@ -490,6 +510,12 @@ def main():
             module.exit_json(msg="Slave stopped", changed=True, queries=executed_queries)
         else:
             module.exit_json(msg="Slave already stopped", changed=False, queries=executed_queries)
+    elif mode in "resetmaster":
+        reset = reset_master(cursor)
+        if reset is True:
+            module.exit_json(msg="Master reset", changed=True, queries=executed_queries)
+        else:
+            module.exit_json(msg="Master already reset", changed=False, queries=executed_queries)
     elif mode in "resetslave":
         reset = reset_slave(cursor, connection_name, channel)
         if reset is True:
diff --git a/test/integration/targets/mysql_replication/tasks/main.yml b/test/integration/targets/mysql_replication/tasks/main.yml
index 3922fd10d7fbcc..9f5c76a7014195 100644
--- a/test/integration/targets/mysql_replication/tasks/main.yml
+++ b/test/integration/targets/mysql_replication/tasks/main.yml
@@ -12,3 +12,7 @@
 # Tests of channel parameter:
 - import_tasks: mysql_replication_channel.yml
   when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7'
+
+# Tests of resetmaster mode:
+- import_tasks: mysql_replication_resetmaster_mode.yml
+  when: ansible_distribution == 'CentOS' and ansible_distribution_major_version >= '7'
diff --git a/test/integration/targets/mysql_replication/tasks/mysql_replication_resetmaster_mode.yml b/test/integration/targets/mysql_replication/tasks/mysql_replication_resetmaster_mode.yml
new file mode 100644
index 00000000000000..19ea4ab4d3aa69
--- /dev/null
+++ b/test/integration/targets/mysql_replication/tasks/mysql_replication_resetmaster_mode.yml
@@ -0,0 +1,48 @@
+# Copyright: (c) 2019, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+# Needs for further tests:
+- name: Stop slave
+  mysql_replication:
+    login_host: 127.0.0.1
+    login_port: "{{ standby_port }}"
+    mode: stopslave
+
+- name: Reset slave all
+  mysql_replication:
+    login_host: 127.0.0.1
+    login_port: "{{ standby_port }}"
+    mode: resetslaveall
+
+# Get master initial status:
+- name: Get master status
+  mysql_replication:
+    login_host: 127.0.0.1
+    login_port: "{{ master_port }}"
+    mode: getmaster
+  register: master_initial_status
+
+# Test resetmaster mode:
+- name: Reset master
+  mysql_replication:
+    login_host: 127.0.0.1
+    login_port: "{{ master_port }}"
+    mode: resetmaster
+  register: result
+
+- assert:
+    that:
+    - result is changed
+    - result.queries == ["RESET MASTER"]
+
+# Get master final status:
+- name: Get master status
+  mysql_replication:
+    login_host: 127.0.0.1
+    login_port: "{{ master_port }}"
+    mode: getmaster
+  register: master_final_status
+
+- assert:
+    that:
+    - master_initial_status.File != master_final_status.File

##### SUMMARY
mysql_replication: add resetmaster choice to mode param
fixes: https://github.com/ansible/ansible/issues/42870

##### ISSUE TYPE
- Feature Pull Request

##### COMPONENT NAME
```lib/ansible/modules/database/mysql/mysql_replication.py```

##### EXAMPLE
```
- name: >
     Run RESET MASTER command which will delete all existing binary log files
     and reset the binary log index file on the master
   mysql_replication:
     mode: resetmaster
```

