Another way to set the mysql root password

89 views
Skip to first unread message

Patrick Ogenstad

unread,
Apr 1, 2014, 11:49:36 AM4/1/14
to ansible...@googlegroups.com
I've just gotten started with Ansible. I must say it's ridiculously simple. :)

I've created a few playbooks and was setting up mysql. The module documentation mentions editing ~/.my.cnf and some links on the net recommend using the file in order to create a idempotent mysql playbook.

However I didn't want to write the password in a textfile.

Instead as a workaround I created two tasks in the playbook:

# This task will fail the first time when the password
# is blank
- name: Ensure MySQL Root Password is changed, this task will fail the first time
  mysql_user: name=root password={{ mysqlrootpass }} login_user=root login_password={{ mysqlrootpass }} state=present
  register: mysqlwithpassword
  ignore_errors: True

- name: Set MySQL root password
  mysql_user: name=root password={{ mysqlrootpass }} login_user=root login_password='' state=present
  when: mysqlwithpassword|failed

The first task will always fail on the first run and when it fail the second task will run. Running the Playbook a second time won't change the system making the playbook idempotent.

Would this be considered bad form in a Ansible sort of way? :) Do you see any downside to solving the problem in this way?

Marko Lisica

unread,
Apr 2, 2014, 4:02:19 AM4/2/14
to ansible...@googlegroups.com
IMHO, as long as this works for you it is okay.

Peter Gehres

unread,
Apr 2, 2014, 12:22:57 PM4/2/14
to ansible...@googlegroups.com
The way we do it it to register a variable on the installation of mysql and set the root password "when: mysqlInstall|changed" 


--
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 ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/388f5255-7704-4eec-8228-175f7dcef8be%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Peter Gehres
Site Reliability Engineer | AppDynamics, Inc.

James Martin

unread,
Apr 4, 2014, 9:55:42 AM4/4/14
to ansible...@googlegroups.com
In case you weren't aware, there is a pretty full featured mysql role on Ansible Galaxy.  That may give you some hints.


- James
Reply all
Reply to author
Forward
0 new messages