DevOps Classroomnotes 20/Mar/2022

Activity 1: Lets install Java 11 (openjdk 11)

  • Our desired state is to install java 11
  • The target os is ubuntu 20.04
  • Manual Steps:
    • Refer Here for the steps
    • Commands
      sudo apt update
      sudo apt install openjdk-11-jdk
  • Lets verify if the manual steps are working correctly or not
    • Lets create a virtual machine
    • Ensure the manual steps are working
    • Please follow the classroom recordings for creating vm and verifying the manual steps
  • In Ansible to automate the manual steps, we have two approaches
    • Adhoc command: We execute the automation by building a command ansible -i inventory -m ping all
    • Playbook:
      • We describe our desired state as a Playbook in a YAML File
      • As of now our playbook can be defined as collection of tasks, In Ansible to execute a task we use Ansible Modules.
      • Ansible module is the smallest unit of ansible where we can express our desired state.
      • Structure:
        “`yaml
      • </ul>
        <hr />
        <ul>
        <li>name: <description>
        hosts: <hosts from inventory>
        become: <yes/no>
        tasks:<ul>
        <li>name: <description of individual step>
        <module>:
        <parameter-1-name>: <parameter-1-value>
        ..
        <parameter-n-name>: <parameter-n-value></li>
        </ul>
        </li>
        <li>“`

      • For running the playbook we use the command ansible-playbook
  • In our case we need to automate the apt command so search for apt in ansible to find the right module Refer Here
  • Refer Here for the changes done.
    Preview
  • Validate the syntax and execute the playbook
    Preview
  • Now lets execute the playbook again
    Preview
  • So when we execute the playbook the desired state is maintained, whether we run playbook once or multiple times.
  • If the result of the execution of desired state is always the same no matter the number of executions, then this property is called as idempotency.
  • As a good practice try to use state as much as possible. Refer Here for the changes.
  • Exercise: Try installing nodejs on the ubuntu vm using ansible

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner