- name: Install Mariadb Server - RedHat
yum:
name:
- mariadb-server
- python3-pip
state: present
when: (ansible_facts['os_family'] == "RedHat")
- name: Install PyMySQL on RedHat
ansible.builtin.pip:
name: PyMySQL
state: present
when: (ansible_facts['os_family'] == "RedHat")
- name: "Start MariaDB"
service:
name: mariadb
state: started
enabled: yes
- name: Creating a database to be used by WordPress - RedHat
mysql_db:
name: "{{ db_wp_name }}"
state: present
when: (ansible_facts['os_family'] == "RedHat")
- name: Create user with password, all database privileges - RedHat
mysql_user:
name: "{{ db_wp_username }}"
password: "{{ db_wp_password }}"
priv: "{{ db_wp_name }}.*:ALL,GRANT"
state: present
when: (ansible_facts['os_family'] == "RedHat")
这些是错误:
TASK [mysql : Creating a database to be used by WordPress - RedHat] ***************************************************************************************************************************************************************************
fatal: [192.168.1.202]: FAILED! => {"changed": false, "msg": "unable to find /root/.my.cnf. Exception message: (1698, \"Access denied for user 'root'@'localhost'\")"}
fatal: [192.168.1.200]: FAILED! => {"changed": false, "msg": "unable to find /root/.my.cnf. Exception message: (1045, \"Access denied for user 'root'@'localhost' (using password: NO)\")"}
在寻找过程中,我尝试使用另一个 yml 来帮助,并在破坏管道的步骤之前调用它。
- name: Stop MySQL
service: name=mysqld state=stopped
- name: set environment variables
shell: systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
- name: Start MySQL
service: name=mysqld state=started
- name: sql query
command: mysql -u root --execute="UPDATE mysql.user SET authentication_string = PASSWORD('{{ mysql_root_password }}') WHERE User = 'root' AND Host = 'localhost';"
- name: sql query flush
command: mysql -u root --execute="FLUSH PRIVILEGES"
- name: Stop MySQL
service: name=mysqld state=stopped
- name: unset environment variables
shell: systemctl unset-environment MYSQLD_OPTS
- name: Start MySQL
service: name=mysqld state=started
但在此之后,现在的错误是:
TASK [mysql : sql query] **********************************************************************************************************************************************************************************************************************
fatal: [192.168.1.200]: FAILED! => {"changed": true, "cmd": ["mysql", "-u", "root", "--execute=UPDATE mysql.user SET authentication_string = PASSWORD('Password123') WHERE User = 'root' AND Host = 'localhost';"], "delta": "0:00:00.087770", "end": "2024-07-02 07:06:47.621171", "msg": "non-zero return code", "rc": 1, "start": "2024-07-02 07:06:47.533401", "stderr": "ERROR 1348 (HY000) at line 1: Column 'authentication_string' is not updatable", "stderr_lines": ["ERROR 1348 (HY000) at line 1: Column 'authentication_string' is not updatable"], "stdout": "", "stdout_lines": []}
fatal: [192.168.1.202]: FAILED! => {"changed": true, "cmd": ["mysql", "-u", "root", "--execute=UPDATE mysql.user SET authentication_string = PASSWORD('Password123') WHERE User = 'root' AND Host = 'localhost';"], "delta": "0:00:00.088495", "end": "2024-07-02 07:06:47.591159", "msg": "non-zero return code", "rc": 1, "start": "2024-07-02 07:06:47.502664", "stderr": "ERROR 1348 (HY000) at line 1: Column 'authentication_string' is not updatable", "stderr_lines": ["ERROR 1348 (HY000) at line 1: Column 'authentication_string' is not updatable"], "stdout": "", "stdout_lines": []}
TASK [mysql : Create user with password, all database privileges - RedHat] *********************************
fatal: [192.168.1.202]: FAILED! => {"changed": false, "msg": "(1290, 'The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement')"}
fatal: [192.168.1.200]: FAILED! => {"changed": false, "msg": "(1290, 'The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement')"}