When I install mysql, default root password is empty. I then use ansible to
set the password:
```
- name: set root password, if it is empty now
mysql_user: login_user=root login_password='' name=root
password='{{desired_pass}}' state=present
```
But 2nd time this playbook runs, the task fails. I can set ignore_errors:
True, but this is prone to other failures as well.
Alternatively, I have the approach of settings the desired password twice:
once logging in with login_password={{desired_pass}}, once with
login_password=''. If one of those succeeds, we're fine:
```
- name: set root password, if it is empty now
mysql_user: login_user=root login_password='{{item}}'
login_host=localhost name=root password='{{desired_pass}}' state=present
with_items:
- '{{root_pass}}'
- ''
register: set_root_pass_result
ignore_errors: True
- fail: msg="could not login with any of the provided passwords"
when: "(set_root_pass_result.results[0].failed is defined) and
(set_root_pass_result.results[1].failed is defined)"
```
Is this supposed to be this tricky, or is there a simpler way?
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/85cebf01-45df-4cf4-9d41-6b42759bf1ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.