---
# tasks file for ansible-wordpress

- name: apt install prerequisites
  apt:
    name: '{{ item }}'
    state: present
    update_cache: yes
    cache_valid_time: 3600
  with_items:
    - nginx-light
    - php5-fpm
    - php5-cli
    - php5-mysql
    - php5-gd
    - cron

- name: Get tarball
  get_url:
    url: 'https://wordpress.org/latest.tar.gz'
    dest: /root/wordpress.tar.gz
    owner: root
    group: root
    mode: '0644'
  register: wordpress_download

- name: Unpack tarball
  when: wordpress_download|changed
  unarchive:
    copy: no
    dest: /var/www
    src: /root/wordpress.tar.gz
    owner: root
    group: root
    mode: '0755'

- name: Configure Wordpress
  template:
    src: wp-config.php.j2
    dest: /var/www/wp-config.php
    owner: root
    group: root
    mode: '0755'

- name: Make plugins, themes installable
  file:
    path: /var/www/wordpress/wp-content
    owner: www-data
    recurse: yes
    state: directory

- name: Add daily backup job
  copy:
    src: backup.sh
    dest: /etc/cron.daily/wordpress
    owner: root
    group: root
    mode: '0755'

- name: Disable default Nginx site
  file:
    path: /etc/nginx/sites-enabled/default
    state: absent
  notify:
    - Restart Nginx

- name: Add Wordpress site to Nginx
  template:
    src: wordpress.j2
    dest: /etc/nginx/sites-enabled/wordpress
    owner: root
    group: root
    mode: '0644'
  notify:
    - Restart Nginx
