Thursday, August 22, 2019

Roles


 We can create roles and assign specific packages by tasks and dependencies to that role.
Roles assigned to machines.

  






 



Roles: builders,server-common,webservers 












Demo: Build Webserver Role

Define webserver,dbserver,common-server roles and apply them.

roles\webserver\vars,tasks,handlers,templates

show_playbook: to see the playbook


roles\webserver\tasks\main.yml
------------------











roles\webserver\vars\main.yml
------------------










roles\webserver\handlers\main.yml






roles\webserver$ local_data
 tree

cd ..\..\webserver.yml playbook
------------------------








 ansible-playbook webserver.yml


Now, see for dbserver.

roles/dbserver/tasks/main.yml
-----------------







cd ../../../dbserver.yml playbook:
--------------------------











roles/server-common/tasks/main.yml
-------


 snmp.yml
---
 

 ../handlers/main.yml
--------------------
 

 ../../site.yml
-----------------

 

 ansible-playbook site.yml

It runs all the internal playbooks.
Shows role name first and task name after that during execution.



No comments:

Post a Comment