DevOps Classroom notes 12/Feb/2026

Inventories

  • Refer Here for official docs
  • inventory contains list of servers/systems to connect to.
  • Inventory can be written in two formats
    • ini format (hosts)
    • yaml format
  • Inventory allows us to group servers
  • prompt: I want to learn writing ansible inventories, Explain ini format
  • by default ansible uses all to represent all hosts in inventory file
  • basic inventory without groups. consider this example1
10.100.0.11
10.100.0.12
10.100.0.13
10.100.0.14
10.100.0.15
10.100.0.16
10.100.0.17
10.100.0.18
10.100.0.19
10.100.0.10

Preview
* in yaml

all:
  hosts:
    10.100.0.11:
    10.100.0.12:
    10.100.0.13:
    10.100.0.14:
    10.100.0.15:
    10.100.0.16:
    10.100.0.17:
    10.100.0.18:
    10.100.0.19:
    10.100.0.10:

  • consider this example2
[webservers]
10.100.0.11
10.100.0.12
10.100.0.13
10.100.0.14
10.100.0.15
10.100.0.16

[dbservers]
10.100.0.17
10.100.0.18
10.100.0.19
10.100.0.10

Preview
* same in yaml

all:
  children:
    webservers:
      hosts:
        10.100.0.11:
        10.100.0.12:
        10.100.0.13:
        10.100.0.14:
        10.100.0.15:
        10.100.0.16:

    dbservers:
      hosts:
        10.100.0.17:
        10.100.0.18:
        10.100.0.19:
        10.100.0.10:

  • Example
[webservers]
www[01:06].example.com
  • The above mentioned inventories are referred as static inventories.
  • Inventories can be dynamic, i.e. it points to

    • an executable (Script) which generates a list of servers in a specific json format
    • Ansible also has plugins to get servers from cloud providers like aws, azure, gcp
  • The default inventory file is in /etc/ansible/hosts

Ansible debug messages

  • Consider the simple playbook
---
- name: sample playbook
  hosts: all
  become: yes
  tasks:
    - name: update packages and install tree
      ansible.builtin.apt:
        name: tree
        update_cache: yes
        state: present
---
- name: sample playbook
  hosts: all
  become: yes
  tasks:
    - ansible.builtin.debug:
        msg: "Installing tree package"
    - name: update packages and install tree
      ansible.builtin.apt:
        name: tree
        update_cache: yes
        state: present
    - ansible.builtin.debug:
        msg: "Installed tree package"
  • Ansible also supports printing verbose information prompt: Ansible playbook verbose levels in a table

Bailout or failing ansible

  • To fail ansible playbook we have a module called fail Refer Here
---
- name: sample bailout playbook
  hosts: all
  become: yes
  tasks:
    - ansible.builtin.fail:
        msg: "Under development"

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
Plugin for Social Media by Acurax Wordpress Design Studio

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