DevOps Classroomnotes 13/Aug/2022

Reusable Assets in Ansible

  • Ansible playbooks can be reused directly
  • Import vs Include: Refer Here
  • Skipping or including only certain tasks in the playbook can be done by tags Refer Here
  • Refer Here for the playbook with tags
  • Run the playbook

Ansible Roles and Collections

  • Ansible hosts reusable roles in Ansible Galaxy Refer Here
  • Lets try to use some role to install mysql Refer Here
  • Lets get the role into the ansible control node
ansible-galaxy install <role-name>
ansible-galaxy install geerlingguy.mysql

* Lets write a playbook to use this role

- name: use existing role
  become: yes
  hosts: dbservers
    - role: geerlingguy.mysql


  • Lets create a ansible role to install tomcat
  • Lets look at conents of the role skeleton
  • In roles we have different folders
    • defaults: for default variable values
    • files: all the static files of the role
    • templates: all the .j2 files containing templates
    • tasks: all the tasks that need to be executed
    • handlers: all the handlers
    • vars: for variables
    • meta: is metadata about role
  • Refer Here for the role created and used in the classroom


  • Install nop commerce on a ubuntu server using the steps Refer Here
  • Create an ansible playbook for deploying nop commerce
  • Create a reusable role for deploying nop commerce

Ansible Parallelism

  • Ansible parallelism can be set by using forks, the default number is 5.
  • Ansible will create 5 parallel connections to 5 servers in inventory, execute the playbook tasks and once they are complete, then next batch of 5 servers start
  • If we need to change the number of forks
ansible-playbook -f <count>

Dynamic inventory

  • Create an executable in any programming language/shell script which will return the server ip address/fqdn i the json format suggested by ansible.
  • Refer Here for aws based dynamic inventory.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About continuous learner

devops & cloud enthusiastic learner