osops-tools-contrib/ansible/lampstack/roles/webserver/tasks/main.yml

110 lines
2.9 KiB
YAML
Executable File

---
- name: Apache and php 5
apt:
name="{{ item }}"
state=latest
update_cache=yes
with_items:
- apache2
- php5
- php5-mysql
- nfs-common
- unzip
- ssmtp
- shell: rm -rf /var/www/html/index.html
args:
warn: no
- name: Creates share directory for wpcontent
file:
path: /var/www/html/wp-content/uploads
state: directory
owner: www-data
group: www-data
- name: Mount the directory using private IP
mount:
name: /var/www/html/wp-content/uploads
src: "{{ hostvars.cloud.database.openstack.private_v4 }}:/storage/wpcontent"
state: mounted
fstype: nfs
when: hostvars.cloud.database.openstack.private_v4 != ""
- name: Mount the directory using public IP
mount:
name: /var/www/html/wp-content/uploads
src: "{{ hostvars.cloud.database.openstack.public_v4 }}:/storage/wpcontent"
state: mounted
fstype: nfs
when: hostvars.cloud.database.openstack.private_v4 == ""
- lineinfile: dest=/etc/apache2/apache2.conf line="ServerName localhost"
- name: Download wordpress
get_url:
url: "{{ app_env.wp_latest | default('https://wordpress.org/latest.tar.gz') }}"
dest: /var/www/latest.tar.gz
- name: Unpack latest wordpress
shell: tar -xf /var/www/latest.tar.gz -C /var/www/html --strip-components=1
args:
warn: no
- name: Create wordpress configuration
shell: cp /var/www/html/wp-config-sample.php /var/www/html/wp-config.php
args:
warn: no
- name: Configure wordpress database, username and password
replace:
dest: /var/www/html/wp-config.php
regexp: "'{{ item.then }}'"
replace: "'{{ item.now }}'"
backup: no
with_items:
- { then: 'database_name_here', now: 'decision2016' }
- { then: 'username_here', now: "{{ db_user }}" }
- { then: 'password_here', now: "{{ db_pass }}" }
- name: Configure wordpress network access using private IP
replace:
dest: /var/www/html/wp-config.php
regexp: "'localhost'"
replace: "'{{ hostvars.cloud.database.openstack.private_v4 }}'"
backup: no
when: hostvars.cloud.database.openstack.private_v4 != ""
- name: Configure wordpress network access using public IP
replace:
dest: /var/www/html/wp-config.php
regexp: "'localhost'"
replace: "'{{ hostvars.cloud.database.openstack.public_v4 }}'"
backup: no
when: hostvars.cloud.database.openstack.private_v4 == ""
- name: Change ownership of wordpress
shell: chown -R www-data:www-data /var/www/html
args:
warn: no
- service: name=apache2 state=restarted enabled=yes
- name: Install wordpress command line tool
get_url:
url: "{{ app_env.wp_cli | default('https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar') }}"
dest: /usr/local/bin/wp
mode: "a+x"
force: no
- name: Download a wordpress theme
get_url:
url: "{{ app_env.wp_theme }}"
dest: /tmp/wptheme.zip
force: yes
- name: Install the theme
shell: unzip -o -q /tmp/wptheme.zip -d /var/www/html/wp-content/themes
args:
warn: no