Um aluno acima de mim teve o mesmo problema que eu, porém, eu tive de assim como ele fazer a correção manualmente, e nos logs da execução do Ansible não informou erro, basicamente o arquivo wp-config.php não tinha sido atualizado pelo with_items:
Meu código:
---
- hosts: wordpress
handlers:
- name: restart apache
service:
name: apache2
state: restarted
become: yes
tasks:
- name: Install apache httpd
ansible.builtin.apt:
update_cache: yes
pkg:
- apache2
- ghostscript
- libapache2-mod-php
- php
- php-bcmath
- php-curl
- php-imagick
- php-intl
- php-json
- php-mbstring
- php-mysql
- php-xml
- php-zip
- mysql-server
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/gabriellopes/AnsibleTraining/ansible-test-wordpress-isolate-db/files/wordpress.conf
dest: /etc/apache2/sites-available/000-default.conf
become: yes
notify:
- restart apache
- 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
force: no
remote_src: yes
become: yes
- name: Configure wp-config with database
ansible.builtin.replace:
path: /srv/www/wordpress/wp-config.php
regexp: '{{item.regexp}}'
replace: '{{item.regexp}}'
with_items:
- {regexp: 'database_name_here', replace: 'wordpress_db'}
- {regexp: 'username_here', replace: 'wordpress_user'}
- {regexp: 'password_here', replace: '12345'}
- {regexp: 'localhost', replace: '10.10.120.61'}
become: yes
- name: Replace a localhost entry searching for a literal string to avoid escaping
ansible.builtin.lineinfile:
path: /srv/www/wordpress/wp-config.php
search_string: '{{item.search_string}}'
line: '{{item.line}}'
with_items:
- { search_string: "define( 'AUTH_KEY', 'put your unique phrase here' ); ", line: "define('AUTH_KEY', '`0CX72H`ijd-#4- K%?xlhlS;UcZ$<.SfN.pnA-hmf:E^OdGHU/TPZ-?&^muq8j');"}
- { search_string: "define( 'SECURE_AUTH_KEY', 'put your unique phrase here' ); ", line: "define('SECURE_AUTH_KEY', '0,z2}gSXTu{hKsUROZ(*wLJ$N+bXR}j).pPK2f$g<KZlDGh(eU;*`^c(U~s0mo-0');"}
- { search_string: "define( 'LOGGED_IN_KEY', 'put your unique phrase here' ); ", line: "define('LOGGED_IN_KEY', '_K4u1V{6WjQ^-x52C4B-eYgti4FVW|QNFdj?DKsc#<$5*SIAWiA!2fF@D~V=4-:H');"}
# Aqui contém o resto do Know Secrets, tirei por segurança, e por que tinha ultrapassado o número de caracteres.
become: yes
- hosts: mysql
handlers:
- name: restart mysql
service:
name: mysql
state: restarted
become: yes
tasks:
- name: Install dependency of db
ansible.builtin.apt:
update_cache: yes
pkg:
- mysql-server
- python3-pymysql
become: yes
- 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
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
host: "{{item}}"
with_items:
- 'localhost'
- '127.0.0.1'
- '10.10.120.60'
become: yes
- name: Configure database
ansible.builtin.replace:
path: /etc/mysql/mysql.conf.d/mysqld.cnf
regexp: '127.0.0.1'
replace: '0.0.0.0'
become: yes
notify:
- restart mysql