0% found this document useful (0 votes)
59 views5 pages

Dev m5 Demo4 v1 h8s nn4pv4q

This document demonstrates how to set up nginx using Ansible roles. It shows how to create an Ansible role, add tasks and handlers to the role, and use the role in a playbook to configure nginx on target servers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views5 pages

Dev m5 Demo4 v1 h8s nn4pv4q

This document demonstrates how to set up nginx using Ansible roles. It shows how to create an Ansible role, add tasks and handlers to the role, and use the role in a playbook to configure nginx on target servers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

DevOps Certification Training

Module 5: Configuration Management


with Ansible
Demo Document - 4

© Brain4ce Education Solutions Pvt. Ltd.


Module 5: Configuration Management with Ansible

Demo – 4: Ansible Roles (Setting up nginx using Ansible Roles)

Note: The text editor used in this demo is vi. You can use any editor of your choice.
Note: Create a custom index.html file and past it inside the roleName/files directory inside your
ansible/roles directory

▪ Navigate to the roles directory in ansible folder

Syntax: cd /etc/ansible/roles

▪ Use the ansible-galaxy command to create a role directory structure

Syntax: ansible-galaxy init roleName

©Brain4ce Education Solutions Pvt. Ltd Page 1


Module 5: Configuration Management with Ansible

▪ Open and edit the main.yml file inside the tasks folder

Syntax: sudo vi roleName/tasks/main.yml

---
- name: Install nginx web server
apt: pkg=nginx state=installed update_cache=true
notify:
- start nginx

- name: Upload
copy: src=index.html dest=/usr/share/nginx/www/ mode=0644
register: php
ignore_errors: True

- name: Remove index.html for host


command: rm /usr/share/nginx/www/index.html
when: php|success

- name: Upload default index.html for host


copy: src=index.html dest=/usr/share/nginx/www/ mode=0644
when: php|failed

▪ Edit the main.yml inside the handlers directory

Syntax: sudo vi roleName/handlers/main.yml

©Brain4ce Education Solutions Pvt. Ltd Page 2


Module 5: Configuration Management with Ansible

---
- name: start nginx
service: name=nginx state=started

▪ Inside the ansible directory create and edit a new playbook to use the role in

Syntax: sudo vi roleName

---
- hosts: all
become: true
vars:
ansible_become_pass: edureka
roles:
- role: demo-role

▪ Now execute the playbook using the ansible-playbook command

Syntax: ansible-playbook playbookName

©Brain4ce Education Solutions Pvt. Ltd Page 3


Module 5: Configuration Management with Ansible

©Brain4ce Education Solutions Pvt. Ltd Page 4

You might also like