Ansible setup mysql root password -
anyone of have idea build yml mysql updating of root password , granting privileges? have created playbook , on fresh install working expected , no issue @ all. when vagrant provision again fails set root password , i'm getting error. below codes
mysql.yml
--- - name: install mysql packages apt: name={{ item }} state=installed update_cache=yes with_items: - mysql-server - mysql-client - python-mysqldb - libmysqlclient-dev - name: drop database {{ dbname }} mysql_db: name: "{{ dbname }}" login_user: "{{ dbuser }}" login_password: "{{ dbpass }}" state: absent delegate_to: "{{ dbhost }}" run_once: true - name: create database {{ dbname }} mysql_db: name: "{{ dbname }}" login_user: "{{ dbuser }}" login_password: "{{ dbpass }}" state: present delegate_to: "{{ dbhost }}" run_once: true - name: ensure mysql running , starts on boot service: name=mysql state=started enabled=true - name: copy .my.cnf file root password credentials template: src=my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600 - name: update mysql root password root accounts "{{ dbpass }}" mysql_user: name={{ dbuser }} host={{ item }} password="{{ dbpass }}" priv="{{ dbname }}.*:all,grant" with_items: - localhost - 127.0.0.1 - name: grant privilege on "{{ dbname }}" "{{ dbuser }}" mysql_user: name: "{{ item.user }}" host: "{{ item.host }}" password: "{{ dbpass }}" login_user: "{{ dbuser }}" login_password: "{{ dbpass }}" priv: "{{ dbname }}.*:all" state: present with_items: - { user: "{{ dbuser }}" , host: localhost } - { user: "{{ dbuser }}" , host: 127.0.0.1 } delegate_to: "{{ dbhost }}" run_once: true - name: ensure anonymous users not in database mysql_user: name='' host={{ item }} state=absent with_items: - 127.0.0.1 - localhost - name: remove test database mysql_db: name=test state=absent
my.cnf.j2
[client] user=root password={{ dbpass }}
defaults/main.yml
--- dbhost: localhost dbname: mydb dbuser: root dbpass: root
i'm able fine if fresh install running second time around gives me error below
seems update .my.cnf
new password before attempt change next task.
and may want use host_all
option when updating password, because with_items
run module several times, , there possibility of same error: change password on first item , can't connect on second item.
Comments
Post a Comment