Ansible:13

DevOps Classroom Series – 02/Jan/2021

Including other playbooks

  • Including other playbooks in current playbook execution
  • Ansible provides two options for executing other playbooks
    • include playbooks
    • import playbooks
  • Major difference b/w include and import tasks are
    • import tasks will be parsed at the begining when you run the playbook
    • include tasks will be parsed at the moment ansible hits
    • Refer Here for the initial changeset with include Preview
    • Refer Here for the initial changeset with import Preview
    • Refer Here
    • For variable usage Refer Here
  • In ansible playbooks we can use tags Refer Here for the changeset Preview Preview Preview
  • Creatng reusable assets with include and import is a challenging job, Ansible has included roles to create reusability
  • Roles move beyond the basic structure of playbooks and provide a framework for fully independent or interdependent, collection of variables, files, tasks, templates and modules
  • Refer Here for official docs
  • Ansible role directory structure Refer Here
  • Refer Here this changeset for sample role structure
  • Refer Here for the tomcat-ubuntu role created
  • Now lets see how to use these roles
  • Refer Here to view the usage of roles Preview
  • These roles gives us flexibility to use lot of alreay written open source community roles which are hosted by ansible in Ansible Galaxy
  • Lets install mysql on ubuntu using ansible role from galaxy Refer Here Preview
  • Refer Here for the change set
  • Now run the ansible-playbook and the mysql service will be installed on the nodes Preview
  • Now lets add some more roles to ansible-playbook
  • Refer Here for the changeset Preview
  • Next Steps
    • Ansible Collections
    • Ansible on Windows
    • Ansible Tower
    • Ansible parallelism forks
    • Exercises
    • Q&A