# Ansible Wordpress Error

**URL:** <https://forum.ansible.com/t/ansible-wordpress-error/35139>\
**Category:** Ansible Developer\
**Tags:** ubuntu\
**Created:** [May 10, 2021, 6:34am UTC](https://forum.ansible.com/t/ansible-wordpress-error/35139 "2021-05-10T06:34:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sameera\_Wijerathna](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Sameera\_Wijerathna](https://forum.ansible.com/u/Sameera_Wijerathna)\
**Post date:** [May 10, 2021, 6:34am UTC](https://forum.ansible.com/t/ansible-wordpress-error/35139/1 "2021-05-10T06:34:31Z")

</div>

I want to setup WordPress[enter image description here][1] using Ansible environment. When i run following YAML files, it gives following error

Connection refused

Error establishing a database connection

**wordpressweb.yaml**

```auto
- hosts: wordpressweb
remote_user: ubuntu
become: yes
become_user: root
become_method: sudo

tasks:
- name: apache must be installed
apt:
name: apache2
state: latest
update_cache: yes
- name: php must be installed
apt:
name: libapache2-mod-php
state: latest
update_cache: yes
- name: mysql mod must be installed
apt:
name: php-mysql
state: latest
update_cache: yes
- name: apache must be running
service:
enabled: yes
name: apache2
state: started
- name: apache must be restarted
service:
enabled: yes
name: apache2
state: restarted
- name: Make sure that there is no index.html
file:
path: /var/www/html/index.html
state: absent
- name: Download wordpress files and extract them to /var/www/html
unarchive:
dest: /var/www/html
remote_src: yes
src: https://wordpress.org/latest.tar.gz
- name: Copy wp-config.php with correct credentials to /var/www/html
copy:
dest: /var/www/html/wordpress/wp-config.php
src: /home/ansible/.ansible/wp-config.php

```

**wordpressdb.yaml**

```auto
- hosts: wordpressdb
remote_user: ubuntu
become: yes
become_user: root
become_method: sudo
tasks:
- name: Make sure that mysql is installed
apt:
name: mysql-server
update_cache: yes
state: latest
- name: Make sure that Mysql is up and running , also enabled at boot
service:
name: mysql
enabled: yes
state: started
- name: Make sure that Pymysql installed
apt:
name:
- python3-pymysql
update_cache: yes
state: latest
- name: Make sure that database wpdb exsists
mysql_db:
name: wpdb
state: present
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Make sure that database user wpuser exists and he has permissions to the wpdb database
mysql_user:
name: wpuser
password: DEVOPS12345
priv: wpdb.*:ALL
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Make sure that database user wpuser exists and he has permissions to the wpdb database
mysql_user:
name: wpuser
password: DEVOPS12345
priv: wpdb.*:ALL
host_all: yes
login_unix_socket: /var/run/mysqld/mysqld.sock

```
