Stack

The next role that we are going to create is the one that is only executed on the host— the ec2_instance group called stack. As with the previous roles, we can run the following command from within our aws-wordpress folder to create the files needed:

$ ansible-galaxy init roles/stack

This role is three roles in one. As with the EC2 role, we are building in logic to execute tasks based on the state of the instance our playbook finds when it first connects. Let's look at the contents of roles/stack/tasks/main.yml first.

The first task in there is executed on both new and existing deployments; it runs a yum update:

- name: update all of the installed packages
yum:
name: "*"
state: "latest"
update_cache: "yes"

Next, we need to know whether WordPress is installed:

- name: are the wordpress files already there?
stat:
path: "{{ wordpress_system.home }}/index.php"
register: wp_installed

The next two tasks include two additional roles; one installs and configures the software stack and the other performs the initial WordPress installation, but only if no existing installation is found:

- name: if no wordpress installed install and configure the software stack
include_role:
name: "stack"
tasks_from: "deploy.yml"
when: wp_installed.stat.exists == False

- name: if no wordpress installed, install it !!!
include_role:
name: "stack"
tasks_from: "wordpress.yml"
when: wp_installed.stat.exists == False

These two roles are condensed versions of the roles we created when we installed WordPress locally.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.69.143