mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-07-27 23:21:27 -07:00
De-duplicate the mysql_command alias
This commit is contained in:
parent
4b6617ab50
commit
90266f1ad5
10 changed files with 16 additions and 37 deletions
|
@ -1,7 +1,4 @@
|
|||
---
|
||||
- name: alias mysql command to include default options
|
||||
set_fact:
|
||||
mysql_command: "mysql -u{{ mysql_user }} -p{{ mysql_password }} --protocol=tcp"
|
||||
|
||||
- vars:
|
||||
mysql_parameters: &mysql_params
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
---
|
||||
- name: alias mysql command to include default options
|
||||
set_fact:
|
||||
mysql_command: "mysql -u{{ mysql_user }} -p{{ mysql_password }} -P{{ mysql_primary_port }} --protocol=tcp"
|
||||
|
||||
- name: set fact tls_enabled
|
||||
command: "{{ mysql_command }} \"-e SHOW VARIABLES LIKE 'have_ssl';\""
|
||||
|
|
|
@ -26,17 +26,17 @@
|
|||
- db.version.major > 8 or (db.version.major == 8 and db.version.minor > 0) or (db.version.major == 8 and db.version.minor == 0 and db.version.release >= 22)
|
||||
- install_type == 'mysql'
|
||||
|
||||
- name: alias mysql command to include default options
|
||||
- name: alias mysql command to include default options except for the port
|
||||
set_fact:
|
||||
mysql_command: "mysql -u{{ mysql_user }} -p{{ mysql_password }} --protocol=tcp"
|
||||
mysql_command_wo_port: "mysql -u{{ mysql_user }} -p{{ mysql_password }} --protocol=tcp -h{{ gateway_addr }}"
|
||||
|
||||
# Preparation:
|
||||
- name: Create user for mysql replication
|
||||
shell: "echo \"CREATE USER '{{ replication_user }}'@'localhost' IDENTIFIED WITH mysql_native_password BY '{{ replication_pass }}'; GRANT REPLICATION SLAVE ON *.* TO '{{ replication_user }}'@'localhost';\" | {{ mysql_command }} -P{{ mysql_primary_port }}"
|
||||
shell: "echo \"CREATE USER '{{ replication_user }}'@'localhost' IDENTIFIED WITH mysql_native_password BY '{{ replication_pass }}'; GRANT REPLICATION SLAVE ON *.* TO '{{ replication_user }}'@'localhost';\" | {{ mysql_command_wo_port }} -P{{ mysql_primary_port }}"
|
||||
when: install_type == 'mysql'
|
||||
|
||||
- name: Create user for mariadb replication
|
||||
shell: "echo \"CREATE USER '{{ replication_user }}'@'localhost' IDENTIFIED BY '{{ replication_pass }}'; GRANT REPLICATION SLAVE ON *.* TO '{{ replication_user }}'@'localhost';\" | {{ mysql_command }} -P{{ mysql_primary_port }}"
|
||||
shell: "echo \"CREATE USER '{{ replication_user }}'@'localhost' IDENTIFIED BY '{{ replication_pass }}'; GRANT REPLICATION SLAVE ON *.* TO '{{ replication_user }}'@'localhost';\" | {{ mysql_command_wo_port }} -P{{ mysql_primary_port }}"
|
||||
when: install_type == 'mariadb'
|
||||
|
||||
- name: Create test database
|
||||
|
@ -50,10 +50,10 @@
|
|||
shell: 'mysqldump -u{{ mysql_user }} -p{{ mysql_password }} -h{{ mysql_host }} --protocol=tcp -P{{ mysql_primary_port }} --all-databases --ignore-table=mysql.innodb_index_stats --ignore-table=mysql.innodb_table_stats --master-data=2 > {{ dump_path }}'
|
||||
|
||||
- name: Restore the dump to replica1
|
||||
shell: '{{ mysql_command }} -P{{ mysql_replica1_port }} < {{ dump_path }}'
|
||||
shell: '{{ mysql_command_wo_port }} -P{{ mysql_replica1_port }} < {{ dump_path }}'
|
||||
|
||||
- name: Restore the dump to replica2
|
||||
shell: '{{ mysql_command }} -P{{ mysql_replica2_port }} < {{ dump_path }}'
|
||||
shell: '{{ mysql_command_wo_port }} -P{{ mysql_replica2_port }} < {{ dump_path }}'
|
||||
|
||||
# Test getprimary mode:
|
||||
- name: Get primary status
|
||||
|
@ -178,10 +178,10 @@
|
|||
|
||||
# Create test table and add data to it:
|
||||
- name: Create test table
|
||||
shell: "echo \"CREATE TABLE {{ test_table }} (id int);\" | {{ mysql_command }} -P{{ mysql_primary_port }} {{ test_db }}"
|
||||
shell: "echo \"CREATE TABLE {{ test_table }} (id int);\" | {{ mysql_command_wo_port }} -P{{ mysql_primary_port }} {{ test_db }}"
|
||||
|
||||
- name: Insert data
|
||||
shell: "echo \"INSERT INTO {{ test_table }} (id) VALUES (1), (2), (3); FLUSH LOGS;\" | {{ mysql_command }} -P{{ mysql_primary_port }} {{ test_db }}"
|
||||
shell: "echo \"INSERT INTO {{ test_table }} (id) VALUES (1), (2), (3); FLUSH LOGS;\" | {{ mysql_command_wo_port }} -P{{ mysql_primary_port }} {{ test_db }}"
|
||||
|
||||
- name: Small pause to be sure the bin log, which was flushed previously, reached the replica
|
||||
ansible.builtin.wait_for:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue