你們中的任何一個人都有一個想法,建立一個MySQL的MySQL更新根密碼和授予特權?我已經創建了我的劇本,並在全新的安裝上按預期工作,沒有任何問題。但是當我再次進行流浪漢配置時,現在無法設置root密碼,並且出現錯誤。下面是我的代碼Ansible設置mysql root密碼
mysql.yml
---
- name: Install the 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 is running and starts on boot
service: name=mysql state=started enabled=true
- name: copy .my.cnf file with root password credentials
template: src=my.cnf.j2 dest=/root/.my.cnf owner=root mode=0600
- name: update mysql root password for all 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 }}" to "{{ 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 are not in the database
mysql_user: name='' host={{ item }} state=absent
with_items:
- 127.0.0.1
- localhost
- name: remove the test database
mysql_db: name=test state=absent
my.cnf.j2
[client]
user=root
password={{ dbpass }}
默認/ main.yml
---
dbhost: localhost
dbname: mydb
dbuser: root
dbpass: root
我能夠只是做一切如果它全新安裝但第二次運行它會給我錯誤
在更新實際的root帳戶之前,您可能需要先更新.my.cnf。 –