Monday 15 April 2013

Install MySQL with ansible on ubuntu -



Install MySQL with ansible on ubuntu -

i have problem installing mysql ansible on vagrant ubuntu,

this mysql part

--- - name: install mysql apt: name: "{{ item }}" with_items: - python-mysqldb - mysql-server - name: re-create .my.cnf file root password credentials template: src: templates/root/.my.cnf dest: ~/.my.cnf owner: root mode: 0600 - name: start mysql service service: name: mysql state: started enabled: true # 'localhost' needs lastly item idempotency, see # http://ansible.cc/docs/modules.html#mysql-user - name: update mysql root password root accounts mysql_user: name: root host: "{{ item }}" password: "{{ mysql_root_password }}" priv: "*.*:all,grant" with_items: - "{{ ansible_hostname }}" - 127.0.0.1 - ::1 - localhost

and have error

failed: [default] => (item=vagrant-ubuntu-trusty-64) => {"failed": true, "item": "vagrant-ubuntu-trusty-64"} msg: unable connect database, check login_user , login_password right or ~/.my.cnf has credentials failed: [default] => (item=127.0.0.1) => {"failed": true, "item": "127.0.0.1"} msg: unable connect database, check login_user , login_password right or ~/.my.cnf has credentials failed: [default] => (item=::1) => {"failed": true, "item": "::1"} msg: unable connect database, check login_user , login_password right or ~/.my.cnf has credentials failed: [default] => (item=localhost) => {"failed": true, "item": "localhost"} msg: unable connect database, check login_user , login_password right or ~/.my.cnf has credentials

my .my.cnf is

[client] user=root password={{ mysql_root_password }}

and when copied on server

[client] user=root password=root

i don't understand why, ~/.my.cnf created

project github

thanks

when mysql-server installed headlessly, there's no password. hence create .my.cnf work, should have blank password line. here's tested .my.cnf:

[client] user=root password=

it's unusual set .my.cnf in vagrant user directory owned root , readable root.

after ensuring password blank in .my.cnf, able set password root in 4 contexts. note fails run after that, since .my.cnf need updated, fails idempotency test.

there's note on ansible mysql_user module page suggests writing password , then writing .my.cnf file. if that, need where clause mysql_user action (probably file stat before that).

even more elegant utilize check_implicit_admin along login_user , login_password. that's beautifully idempotent.

as 3rd way, perhaps check_implicit_admin makes easier.

here's successful playbook showing above, tested few fresh servers. kinda proud of this. note .my.cnf unnecessary of this.

--- - hosts: mysql vars: mysql_root_password: fart tasks: - name: install mysql apt: name={{ item }} update_cache=yes cache_valid_time=3600 state=present sudo: yes with_items: - python-mysqldb - mysql-server #- name: re-create cnf # copy: src=.my.cnf dest=~/.my.cnf owner=ubuntu mode=0644 # sudo: yes - name: start mysql service sudo: yes service: name: mysql state: started enabled: true - name: update mysql root password root accounts sudo: yes mysql_user: name: root host: "{{ item }}" password: "{{ mysql_root_password }}" login_user: root login_password: "{{ mysql_root_password }}" check_implicit_admin: yes priv: "*.*:all,grant" with_items: - "{{ ansible_hostname }}" - 127.0.0.1 - ::1 - localhost

(edit- removed my.cnf)

mysql ubuntu vagrant ansible

No comments:

Post a Comment