DevOps Classroom notes 05/Mar/2025

Writing Playbooks

Ansible Module

  • Ansible module is an smallest unit of work in ansible
  • We use modules in tasks and handler
  • module does a certain work with a desired state (generally)
  • Ansible has lots of modules
  • basic task syntax in playbook
- name: do something
  <module-name>:
    arg-1-name: arg-1-value
    ..
    arg-n-name: arg-n-value
    state: <desired-state>
  • Lets look at a sample
- name: create a file
  ansible.builtin.file:
    path: /tmp/1.txt
    state: touch
  • Modules can also be executed from adhoc commands
ansible -m ping all
ansible -m ansible.builtin.file -a "path=/tmp/1.txt state=touch" all

Update Ways of Working

  • Ensure you have working manual commands
  • For each command try to find an equivalent ansible module which makes this a task

Install apache server on ubuntu 24.04

  • Manual steps
sudo apt update
sudo apt install apache2 -y
  • Now verify the installation by navigating to http://<public-ip>
    Preview
  • Now lets start writing playbook
  • Create a new directory with two files apache.yaml and hosts
  • Playbook
---
- name: installing apache
  hosts: all
  become: yes
  tasks:
    - name: install apache
      ansible.builtin.apt:
        name: apache2
        update_cache: yes
        state: present
  • inventory
172.31.4.82

Preview

How to Find the module in ansible

  • Get to know your command
    Preview
  • To understand modules documentation Watch classroom recording

Executing Playbook

ansible-playbook -i hosts <playbook>
  • First check syntax
ansible-playbook --syntax-check <playbook>

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

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

Please turn AdBlock off
Animated Social Media Icons by Acurax Responsive Web Designing Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube