Skip to content

Commit

Permalink
Merge pull request #532 from ptomas-adacis/master
Browse files Browse the repository at this point in the history
Hide passwords during execution
  • Loading branch information
geerlingguy authored Dec 6, 2023
2 parents 8f0eef9 + b04a0ca commit 8c87b67
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ Replication settings. Set `mysql_server_id` and `mysql_replication_role` by serv

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)

```yaml
mysql_hide_passwords: false
```

Do you need to hide tasks' output which contain passwords during the execution ?

### Later versions of MySQL on CentOS 7

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:
Expand Down
2 changes: 2 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ mysql_replication_master_inventory_host: "{{ mysql_replication_master }}"

# Same keys as `mysql_users` above.
mysql_replication_user: []

mysql_hide_passwords: false
6 changes: 5 additions & 1 deletion tasks/replication.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
password: "{{ mysql_replication_user.password }}"
priv: "{{ mysql_replication_user.priv | default('*.*:REPLICATION SLAVE,REPLICATION CLIENT') }}"
state: present
no_log: "{{ mysql_hide_passwords }}"
when:
- mysql_replication_role == 'master'
- mysql_replication_user.name is defined
Expand All @@ -17,17 +18,19 @@
mode: getreplica
login_user: "{{ mysql_root_username }}"
login_password: "{{ mysql_root_password }}"
no_log: "{{ mysql_hide_passwords }}"
ignore_errors: true
register: slave
when:
- mysql_replication_role == 'slave'
- (mysql_replication_master | length) > 0
tags: ['skip_ansible_galaxy']

# https://github.com/ansible/ansible/issues/82264
- name: Check master replication status.
mysql_replication:
mode: getprimary
delegate_to: "{{ mysql_replication_master_inventory_host }}"
delegate_to: "{{ mysql_replication_master_inventory_host | default(omit, true) }}"
register: master
when:
- (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)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)

Check warning on line 36 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

36:161 [line-length] line too long (205 > 160 characters)
Expand All @@ -43,6 +46,7 @@
master_password: "{{ mysql_replication_user.password }}"
master_log_file: "{{ master.File }}"
master_log_pos: "{{ master.Position }}"
no_log: "{{ mysql_hide_passwords }}"
ignore_errors: true
when:
- (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)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)

Check warning on line 52 in tasks/replication.yml

View workflow job for this annotation

GitHub Actions / Lint

52:161 [line-length] line too long (205 > 160 characters)
Expand Down
5 changes: 5 additions & 0 deletions tasks/secure-installation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
password: "{{ mysql_user_password }}"
priv: '*.*:ALL,GRANT'
state: present
no_log: "{{ mysql_hide_passwords }}"
when: mysql_user_name != mysql_root_username

# Has to be after the password assignment, for idempotency.
Expand All @@ -15,6 +16,7 @@
dest: "{{ mysql_user_home }}/.my.cnf"
owner: "{{ mysql_user_name }}"
mode: 0600
no_log: "{{ mysql_hide_passwords }}"
when: >
mysql_user_name != mysql_root_username
and (mysql_install_packages | bool or mysql_user_password_update)
Expand Down Expand Up @@ -44,6 +46,7 @@
mysql -u root -NBe
"ALTER USER '{{ mysql_root_username }}'@'{{ item }}'
IDENTIFIED WITH mysql_native_password BY '{{ mysql_root_password }}'; FLUSH PRIVILEGES;"
no_log: "{{ mysql_hide_passwords }}"
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
when: >
((mysql_install_packages | bool) or mysql_root_password_update)
Expand All @@ -54,6 +57,7 @@
ansible.builtin.shell: >
mysql -NBe
'SET PASSWORD FOR "{{ mysql_root_username }}"@"{{ item }}" = PASSWORD("{{ mysql_root_password }}"); FLUSH PRIVILEGES;'
no_log: "{{ mysql_hide_passwords }}"
with_items: "{{ mysql_root_hosts.stdout_lines|default([]) }}"
when: >
((mysql_install_packages | bool) or mysql_root_password_update)
Expand All @@ -67,6 +71,7 @@
owner: root
group: root
mode: 0600
no_log: "{{ mysql_hide_passwords }}"
when: mysql_install_packages | bool or mysql_root_password_update

- name: Get list of hosts for the anonymous user.
Expand Down
2 changes: 1 addition & 1 deletion tasks/users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
append_privs: "{{ item.append_privs | default('no') }}"
encrypted: "{{ item.encrypted | default('no') }}"
with_items: "{{ mysql_users }}"
no_log: true
no_log: "{{ mysql_hide_passwords }}"

0 comments on commit 8c87b67

Please sign in to comment.