How to do it…

  1. In a previous recipe, we created an Elastic IP and registered the value of the output. We are going to use that and add it to a group called phonebook-infra:
- name: Adding Elastic IP to the phonebook-infra
add_host:
hostname: "{{ eip.public_ip }}"
groups: phonebook-infra
  1. Once we are done with the add_host task in the EC2 role, our playbook can deploy the application by calling both the EC2 role and phonebook role like this:
---
- hosts: localhost
roles:
- ec2
- hosts: phonebook-infra
roles:
- phonebook

To understand the phonebook role better, we can refer to Chapter 1, Getting Started with Ansible and Cloud Management of this book. This playbook will create an EC2 instance and deploy the phonebook application on that instance. Since we are using a single instance, we will use SQLite as the database. 

 

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

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