DevOps Classroomnotes 27/May/2023

Ansible

  • Ansible can communicate with nodes by using two approaches
    • adhoc commands:
      • We build a command for desired state
    • playbook:
      • We create a file where we express desired state
      • This is recommended approach for repetitive activites

Playbook

  • We have taken a sample playbook
---
- name: hello ansible
  hosts: all
  become: yes
  tasks:
    - name: update packages and install tree
      apt:
        name: tree
        state: present
        update_cache: yes
  • We executed playbook
    Preview
  • Basic Playbook semantics
    Preview
  • In ansible the smallest unit of work is perfomed by module

YAML

  • YAML vs JSON
    Preview
  • Refer Here for yaml syntax from ansible

Ways of Working (WoW):

  • list down all the manual steps
  • Ensure all the steps are working
  • For each step find a module and express the desired state

Activity 1: Install apache server

  • Manual steps
sudo apt update
sudo apt install apache2 -y
  • Verify the installation http://<public-ip>
    Preview
  • Refer Here for ansible yaml syntax for playbook
  • Finding the module:
    • search google with <command> in ansible
      Preview
    • search from ansible docs Refer Here
      Preview
  • all the commands for installation are executed with sudo
---
- name: install apache server
  hosts: all
  become: yes
  tasks:
    - name: install apache
      ansible.builtin.apt:
        name: apache2
        update_cache: yes
        state: present
  • create inventory
172.31.27.136
  • Run the command ansible-playbook -i <inventory-path> <playbook-path>
    Preview
  • Execute the playbook
    Preview
  • verify the apache
    Preview

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner