0% found this document useful (0 votes)
18 views

Guided Practice_Using Ansible Roles

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Guided Practice_Using Ansible Roles

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Guided Practice: Using Ansible Roles

Outcome:
Ansible’s strengths include the ability to facilitate the configuration of UNIX, Linux, Windows, and Mac operating systems that
include groups that may be dependent on other groups which can involve the secure backing up of data, configuring firewalls,
creating users and groups, and replication. In this Guided Practice, you will create a modular, reusable library of code for
application configurations using ansible-galaxy to set up roles to install Apache.

Resources Needed:
• VCASTLE Pod configured for the class, utilizing CentOS and Ubuntu machines.

• User privileges with sudo capabilities.

Level of Difficulty:
Moderate

Deliverables:
Deliverables are highlighted in red font or marked with a red picture border around the screenshot. Ensure your username or
student ID is visible in all submitted screenshots.

General Considerations:
You should be familiar with Linux and Windows networking. Secure Shell (ssh) is installed and configured on the Ubuntu server
from a prior Guided Practice. Ansible is installed and configured on your CentOS Computer, and you have completed all the
previous exercises.

Page | 1
Edit the Ansible Inventory (host) File

1. First, you will edit the Ansible Inventory (host) file to reflect your network architecture, if necessary.
View the inventory (hosts) file, and ensure your inventory file reflects the architecture of your network as shown below
and includes the [win:vars] section.

Page | 2
Set Up the Directory Structure
2. On the CentOS server, type the following commands in a shell (substituting the appropriate username for studentID for
all steps):
ansible-galaxy init /home/studentID/ansible/roles/apache --offline
tree /home/studentID/ansible/roles/apache
Take a screenshot that resembles the one below, and paste it in your Lab Report.

Page | 3
Create the Required Files to Install Apache Using Roles
Note: If Apache has been previously installed, this playbook will run without making unnecessary changes.
3. Create a playbook called install.yml.In your shell, type the following:
cd /home/studentID/ansible/roles/apache/tasks/
nano install.yml

Type the lines below in your playbook – take a screenshot for your lab report:
---
- name: Install apache web server
apt:
name: apache2
state: latest

Page | 4
4. Create another playbook called service.yml. In your shell, type:
nano service.yml
Type the lines below in your playbook – take a screenshot for your lab report:
---
- name: start apache webserver
service:
name: apache2
state: started
enabled: true

Page | 5
5. Create a third playbook called main.yml. In your shell, type:
nano main.yml
Type the lines below in your playbook – take a screenshot for your lab report:
---
# tasks file for apache
- import_tasks: install.yml
- import_tasks: service.yml

Page | 6
Create a Playbook to Install Apache Using Your Previously Created Structure
6. In your shell, type:
cd /home/studentID/ansible/
nano runsetup.yml

Type the lines below in your playbook – take a screenshot for your lab report:
---
- hosts: webserver
become: true
roles:
Page | 7
- apache

7. Check the syntax of your playbook, correct errors if any are present, then run the playbook – take a screenshot of the
successful outcome of these commands for your Lab Report. In your shell type:
ansible-playbook runsetup.yml --syntax-check
ansible-playbook runsetup.yml --ask-become-pass

Page | 8
Guided Practice Questions:
In your Guided Practice Lab Report, answer the following questions about this learning activity. Some may require research.
 How do roles facilitate adding new applications or configurations (installing emacs for example)?

Page | 9

You might also like