Skip to main content

Two tier Design Part 2 Install services

Updated Dec 08, 2020 ·

Overview

This lab continues the two-tier application build by installing and starting the services required by the web and load balancer hosts.

Diagram:

Here we'll be installing services on our webservers and loadbalancer.

  • webservers: Apache and PHP
  • loadbalancers: Apache

After installing the services, they would also need to be started.

For the playbook:

install-services.yml
# install-services.yml
---
# install-services.yml
---

- name: Install Apache on loadbalancer
become: true
hosts: loadbalancers
tasks:
- name: Install Apache on loadbalancer
yum:
name: httpd
state: present
- name: Starts the service/s
service:
name: httpd
state: started
enabled: yes

- name: Install Apache and PHP on webservers
become: true
hosts: webservers
tasks:
- name: Install Apache and PHP on webservers
yum:
name:
- httpd
- php
state: present
- name: Starts the service/s
service:
name: httpd
state: started
enabled: yes

To test,

$ ansible-playbook playbooks/install-services.yml

Now, as our playbooks get longer as we add more plays and tasks, it will be troublesome to check all the playbooks. One way to easily point out on which Nodes something went wrong or which part failed, is to check the play recap and summary once the playbook is done.