DevOps Classroom notes 12/Jun/2026

Ansible Playbooks

  • Ansible playbook is written in a YAML file and is a collection of plays.
  • Each Play is a collection of tasks (and handlers).
  • Each task represents a unit of activity which is achieved by a module.

Ansible Module

  • This is the smallest (atomic) unit in Ansible where we can express desired state.
  • Ansible comes inbuilt with many modules. In addition, we can add community modules or develop our own.

sample playbook:

---
- name: demo
  become: yes
  hosts: ipaddress
  tasks:
    - name: Install apache httpd (state=present is optional)
      ansible.builtin.apt:
        name: apache2
        update_cache: yes
        state: present

    - name: restart service apcahe
      ansible.builtin.systemd_service:
        name: apache2
        enabled: yes
        state: restarted

    - name: Download foo.conf
      ansible.builtin.get_url:
        url: https://templatemo.com/tm-zip-files-2020/templatemo_589_lugx_gaming.zip
        dest: /tmp/templatemo_589_lugx_gaming.zip
        mode: '0440'

---
- name: demo
  become: yes
  hosts: all
  tasks:
    - name: Install the latest version of Apache
      ansible.builtin.dnf:
        name: httpd
        state: latest

    - name: restart service apcahe
      ansible.builtin.systemd_service:
        name: httpd
        enabled: yes
        state: restarted

Running the Playbook

ansible-playbook -i hosts apache.yaml

Leave a comment

Turn on JavaScript to leave a comment.

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

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%