Manual

Structure helpers

Playbooks, roles, collections, inventory and variables as calls: where the multi-file editing goes away.

These are where the multi-file editing goes away.

playbook("site.yml",
         play("all", become=True, roles=["common"]),
         play("web", become=True, roles=["acme.stack.nginx"]))

role("common",
     tasks=[{"name": "set the timezone",
             "community.general.timezone": {"name": "{{ timezone }}"}}],
     defaults={"timezone": "UTC"},
     handlers=[...], vars={...}, meta={...},
     files={"robots.txt": "User-agent: *\n"},
     templates={"site.conf.j2": "listen {{ nginx_port }};\n"})

collection("acme.stack", version="1.2.0",
           roles={"nginx": dict(tasks=[...], defaults={"nginx_port": 80})},
           plugins={"modules/acme_thing.py": "..."})

inventory({
    "web": ["web1.example.com", "web2.example.com"],
    "db": {"hosts": {"db1": {"ansible_host": "10.0.0.5"}},
           "vars": {"postgresql_version": 16}},
    "all": {"children": ["web", "db"]},
})

group_vars("all", timezone="Europe/Amsterdam")
host_vars("web1.example.com", ansible_host="10.0.0.1")

role() returns the name to put in a play (dotted when it lives in a collection), and only writes the parts you pass.

Each of these calls is in the reference, with its arguments: Declarations.

When the script describes itself#

An inventory() and a site.yml written by hand are one way. The other is to describe the groups, the variables and the stages, and have the inventory, the group_vars and site.yml written from that: Describing a script. Files the script declares itself win over what a description would write.

The source of this page

    Type to search. ↑ ↓ to move, enter to open.