Handling and verifying hosts file

Every time I create a new playbook, I want to verify, that I grouped the hosts correctly. Here I is my "How I do it".

First of all. My hosts files are always in the yaml format, even tough it could be an INI file. I am using this format, as all playbooks use this format as well.

Example hosts.yaml

all:
    hosts:
    children:
        web:
            hosts:
                webserver1.codesie.ch:
        db:
            hosts:
                dbserver1.codesie.ch:

Show all hosts

ansible all --list-hosts

Output

hosts (2):
    webserver1.codesie.ch
    dbserver1.codesie.ch

Show hosts of a group

ansible -l web all --list-hosts

Output

hosts (1):
    webserver1.codesie.ch

Source

Official Inventory Doc