DevOps Classroom Series – 22/Dec/2020

How does ansible execute playbooks/commands

  • Lets login into ansible control server
  • When ansible is installed the following folders will be created
    • /etc/ansible: This folder will consist of ansible configuration file ansible.cfg, default inventory and roles folder Preview
    • /usr/bin/: These are executable of ansible Preview
  • Lets review ansible configuration file
  • To find the ansible modules path execute ansible –version Preview Preview
  • So now we know where the modules are located.
  • Once we set ansible-playbook/adhoc command for execution
    • Ansible will search for the modules used and once the module is found how is it transported and executed on node

Module Transport and Execution

  • Ansible will locate the module file on the local file system on ansible control server and read it into memory & then it adds the arguments passed to the module.
  • Then the Ansible code is added to the file object in memory
  • This collection is compressed, Base-64 encoded and then wrapped in a script.
  • Now Ansible will open SSH connection to the remote node, creates a temporary directory and closes the connection
  • Ansible will open another SSH connection in order to writes out the wrapped script (the result of local module files, module arguments and ansible code) into a file within the temporary directory created.
  • Finally ansible will open a third connection in order to execute the script and delete the temporary directory and all it contents.
  • The module results are captured from stdout in the JSON format, which Ansible will parse and handle appropriately.
  • Ansible will close the third connection before the module is complete and SSH back into the host to check the status of task after prescrible period until the module is complete or timeout has been reached.

Scenarios:

  1. We have two environments Dev and QA
    1. For Dev Environment we have admin user to be configured for ansible as ansible
    2. For QA Environment we have admin user (Service account) to be configured for ansible as jenkins
  2. We have to configure ansible to work with python3 for all Dev Environments
  3. We have to run the web playbook only on Web Servers, app playbook only on app servers and db playbook only on db servers? How can i do this grouping

Solution for Scenarios

  • To Solve the above Scenarios, we need to understand
    • Inventories
    • Playbook parsing

Leave a Reply

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

About learningthoughtsadmin