Skip to content

Commit 8c87b67

Browse files
authored
Merge pull request #532 from ptomas-adacis/master
Hide passwords during execution
2 parents 8f0eef9 + b04a0ca commit 8c87b67

File tree

5 files changed

+19
-2
lines changed

5 files changed

+19
-2
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ Replication settings. Set `mysql_server_id` and `mysql_replication_role` by serv
166166

167167
If the replication master has different IP addresses where you are running ansible and where the mysql replica is running, you can *optionally* specify a `mysql_replication_master_inventory_host` to access the machine (e.g. you run ansible on your local machine, but the mysql master and replica need to communicate on a different network)
168168

169+
```yaml
170+
mysql_hide_passwords: false
171+
```
172+
173+
Do you need to hide tasks' output which contain passwords during the execution ?
174+
169175
### Later versions of MySQL on CentOS 7
170176

171177
If you want to install MySQL from the official repository instead of installing the system default MariaDB equivalents, you can add the following `pre_tasks` task in your playbook:

defaults/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,5 @@ mysql_replication_master_inventory_host: "{{ mysql_replication_master }}"
132132

133133
# Same keys as `mysql_users` above.
134134
mysql_replication_user: []
135+
136+
mysql_hide_passwords: false

tasks/replication.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
password: "{{ mysql_replication_user.password }}"
77
priv: "{{ mysql_replication_user.priv | default('*.*:REPLICATION SLAVE,REPLICATION CLIENT') }}"
88
state: present
9+
no_log: "{{ mysql_hide_passwords }}"
910
when:
1011
- mysql_replication_role == 'master'
1112
- mysql_replication_user.name is defined
@@ -17,17 +18,19 @@
1718
mode: getreplica
1819
login_user: "{{ mysql_root_username }}"
1920
login_password: "{{ mysql_root_password }}"
21+
no_log: "{{ mysql_hide_passwords }}"
2022
ignore_errors: true
2123
register: slave
2224
when:
2325
- mysql_replication_role == 'slave'
2426
- (mysql_replication_master | length) > 0
2527
tags: ['skip_ansible_galaxy']
2628

29+
# https://github.com/ansible/ansible/issues/82264
2730
- name: Check master replication status.
2831
mysql_replication:
2932
mode: getprimary
30-
delegate_to: "{{ mysql_replication_master_inventory_host }}"
33+
delegate_to: "{{ mysql_replication_master_inventory_host | default(omit, true) }}"
3134
register: master
3235
when:
3336
- (slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Replica is defined and not slave.Is_Replica) or (slave.Is_Slave is not defined and slave.Is_Replica is not defined and slave is failed)
@@ -43,6 +46,7 @@
4346
master_password: "{{ mysql_replication_user.password }}"
4447
master_log_file: "{{ master.File }}"
4548
master_log_pos: "{{ master.Position }}"
49+
no_log: "{{ mysql_hide_passwords }}"
4650
ignore_errors: true
4751
when:
4852
- (slave.Is_Slave is defined and not slave.Is_Slave) or (slave.Is_Replica is defined and not slave.Is_Replica) or (slave.Is_Slave is not defined and slave.Is_Replica is not defined and slave is failed)

tasks/secure-installation.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
password: "{{ mysql_user_password }}"
77
priv: '*.*:ALL,GRANT'
88
state: present
9+
no_log: "{{ mysql_hide_passwords }}"
910
when: mysql_user_name != mysql_root_username
1011

1112
# Has to be after the password assignment, for idempotency.
@@ -15,6 +16,7 @@
1516
dest: "{{ mysql_user_home }}/.my.cnf"
1617
owner: "{{ mysql_user_name }}"
1718
mode: 0600
19+
no_log: "{{ mysql_hide_passwords }}"
1820
when: >
1921
mysql_user_name != mysql_root_username
2022
and (mysql_install_packages | bool or mysql_user_password_update)
@@ -44,6 +46,7 @@
4446
mysql -u root -NBe
4547
"ALTER USER '{{ mysql_root_username }}'@'{{ item }}'
4648
IDENTIFIED WITH mysql_native_password BY '{{ mysql_root_password }}'; FLUSH PRIVILEGES;"
49+
no_log: "{{ mysql_hide_passwords }}"
4750
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
4851
when: >
4952
((mysql_install_packages | bool) or mysql_root_password_update)
@@ -54,6 +57,7 @@
5457
ansible.builtin.shell: >
5558
mysql -NBe
5659
'SET PASSWORD FOR "{{ mysql_root_username }}"@"{{ item }}" = PASSWORD("{{ mysql_root_password }}"); FLUSH PRIVILEGES;'
60+
no_log: "{{ mysql_hide_passwords }}"
5761
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
5862
when: >
5963
((mysql_install_packages | bool) or mysql_root_password_update)
@@ -67,6 +71,7 @@
6771
owner: root
6872
group: root
6973
mode: 0600
74+
no_log: "{{ mysql_hide_passwords }}"
7075
when: mysql_install_packages | bool or mysql_root_password_update
7176

7277
- name: Get list of hosts for the anonymous user.

tasks/users.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
append_privs: "{{ item.append_privs | default('no') }}"
1010
encrypted: "{{ item.encrypted | default('no') }}"
1111
with_items: "{{ mysql_users }}"
12-
no_log: true
12+
no_log: "{{ mysql_hide_passwords }}"

0 commit comments

Comments
 (0)