playbooks/wordpress/playbook.yml

70 lines
1.9 KiB
YAML
Raw Normal View History

2022-08-02 01:11:22 +00:00
#################################################
# DO Community Playbooks: Docker
#################################################
---
- hosts: all
become: true
vars_files:
- vars/default.yml
tasks:
- name: Pull Wordpress image
docker_image:
name: "{{ image_name }}"
source: pull
force_source: yes
- name: Ensure SSH Directory exists
file:
path: "/var/lib/{{ http_host }}"
state: directory
group: www-data
owner: www-data
mode: 0700
- name: Create Wordpress container
docker_container:
name: "{{ container_name }}"
image: "{{ image_name }}"
state: started
restart_policy: "unless-stopped"
env:
WORDPRESS_DB_HOST: "{{ db_host }}"
WORDPRESS_DB_USER: "{{ db_user }}"
WORDPRESS_DB_PASSWORD: "{{ db_pass }}"
WORDPRESS_DB_NAME: "{{ db_name }}"
links:
- "mariadb:db"
published_ports:
- "127.0.0.1:{{ web_port }}:80"
volumes:
- "/var/lib/{{ http_host }}:/var/www/html"
- name: Check if Nginx conf file exists
stat: path="/etc/nginx/sites-available/{{ http_conf }}"
register: status
- name: No need to reload Nginx
debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }}
- name: Set Nginx conf file
when: status.stat.exists == false
template:
src: "files/nginx.conf.j2"
dest: "/etc/nginx/sites-available/{{ http_conf }}"
- name: Enable new site
when: status.stat.exists == false
file:
src: "/etc/nginx/sites-available/{{ http_conf }}"
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
state: link
notify: Reload Nginx
handlers:
- name: Reload Nginx
service:
name: nginx
state: reloaded