Ao realizar o passo de alteração do arquivo /srv/www/wordpress/wp-config.php e ao executar o playbook o erro ' Error establishing a database connection' fiz a pesquisa do erro relacionado, a pesquisa apontou alguma divergencia no arquivo de configuração nos campos alterados, porem ainda não consegui indentificar o erro caso tenha algum. Segue meu playbook criado para essa atividade:
---
- hosts: all
handlers:
- name: restart apache
service:
name: apache2
state: restarted
become: yes
tasks:
- name: Install dependencias
ansible.builtin.apt:
pkg:
- apache2
- ghostscript
- libapache2-mod-php
- mysql-server
- php
- php-bcmath
- php-curl
- php-imagick
- php-intl
- php-json
- php-mbstring
- php-mysql
- php-xml
- php-zip
- python3-pymysql
state: latest
update_cache: yes
become: yes
- name: Create a directory if it does not exist
ansible.builtin.file:
path: /srv/www
state: directory
owner: www-data
group: www-data
become: yes
- name: Unarchive a file that needs to be downloaded (added in 2.0)
ansible.builtin.unarchive:
src: https://wordpress.org/latest.tar.gz
dest: /srv/www
remote_src: yes
become: yes
- name: Copy file with owner and permissions
ansible.builtin.copy:
src: /home/ansible/ansible/files/wordpress.conf
dest: /etc/apache2/sites-available/000-default.conf
become: yes
notify:
- restart apache
- name: Create a new database with name 'wordpress_db'
community.mysql.mysql_db:
name: wordpress_db
state: present
login_unix_socket: /run/mysqld/mysqld.sock
become: yes
- name: Create database user with name 'wordpress_user' and password '12345' with all database privileges
community.mysql.mysql_user:
name: wordpress_user
password: 12345
priv: wordpress-db.*:SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,ALTER
state: present
login_unix_socket: /run/mysqld/mysqld.sock
become: yes
- name: Copy file with owner and permissions
ansible.builtin.copy:
src: /srv/www/wordpress/wp-config-sample.php
dest: /srv/www/wordpress/wp-config.php
remote_src: yes
become: yes
- name: Configure wp-config.php with database
ansible.builtin.replace:
path: /srv/www/wordpress/wp-config.php
regexp: '{{ item.regexp }}'
replace: '{{ item.replace }}'
with_items:
with_items:
- { regexp: 'database_name_here', replace: 'wordpress_db'}
- { regexp: 'username_here', replace: 'wordpress_user'}
- { regexp: 'password_here', replace: '12345'}
become: yes