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 ...

Get Learn Ansible now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.