← All TILs

ansible

64 TILs filed under ansible. Atom feed for this topic.

Reading order: Ansible development environment

  1. Locking an Ansible development environment: pip, venv, pip-tools, uv or an execution environment
  2. Pinning ansible-core with pip-tools, uv and Poetry
  3. Building an Ansible execution environment from a locked requirements file
  4. Where to run an Ansible development environment: venv, Dev Container, Remote-SSH, code-server or Dev Spaces
  5. Ansible Development Tools (ADT): one install, and the Python version decides what you get
  6. Committing the VS Code Ansible settings with the repository
  7. Running playbooks locally in the execution environment production uses
  8. An Ansible Dev Container: choosing the scaffolded config, Podman, and the EE navigator falls back to
  9. A shared Ansible dev server for VS Code Remote-SSH, built with Ansible
  10. Linting Ansible before it reaches Git: `--fix` in the editor, the same ansible-lint in CI
  11. Scaffolding with ansible-creator: roles inside a collection, and what to change in the output
  12. A collection-aware venv with ansible-dev-environment (ade): what it installs, what it edits, and how to pin it

Reading order: Shaping data in Ansible

  1. One sudoers line per command with community.general.dict_kv: building a list of dicts from a list of values
  2. Lists and dicts back and forth: dict2items, items2dict and zip on role, Foreman and Proxmox data
  3. Merging dicts with combine: PostgreSQL settings in layers, Quadlet units from a base
  4. Picking from a list of dicts: selectattr, rejectattr and map on Proxmox guests and host facts
  5. subelements versus product: Quadlet volume directories and PostgreSQL pg_hba rules
  6. Set operations on lists: declared Proxmox guests against the cluster, and why the order changes between runs
  7. Strings into structures: df with split and regex_findall, findmnt with from_json
  8. default, default(omit), mandatory and ternary: sudo rules that don't set every field
  9. Forcing types: extra vars arrive as strings, and ansible-core 2.19 stopped guessing
  10. Writing data out: a Caddy JSON configuration with to_nice_json, sort_keys and indent
  11. Data from other hosts: pg_hba rules from the app servers' facts, with hostvars and extract
  12. groupby, groupby_as_dict and lists_mergeby: Proxmox guests by node, and joined to what the team declares
  13. json_query or native filters: part 4's Proxmox selections written in JMESPath
  14. Network data with ansible.utils: checking pg_hba subnets and numbering Proxmox guests
  15. set_fact in a loop or one expression: part 11's pg_hba rules, built both ways
  16. Text on lists: building a systemd ExecStart line with regex_replace, join and replace

Reading order: Ansible inventory from scratch

  1. Hosts and groups: the two groups every inventory has, all and ungrouped
  2. An inventory as a directory: a hosts file without variables, and group_vars per role
  3. INI or YAML for the hosts file, and why variables stay out of both
  4. Connection variables: ansible_host, ansible_port, ansible_user and ansible_connection, with ssh, docker and local
  5. Environments in an Ansible inventory: separate directories, or prod and staging as groups
  6. Checking what Ansible sees: ansible-inventory --graph, --list and --host
  7. Facts or variables: what Ansible discovers (as-is) against what you declare (to-be)
  8. Where a variable should live: role defaults, group_vars, host_vars, and extra vars as safety switches
  9. Inventory precedence: all, parent, child, host, and what ansible_group_priority really does
  10. Secrets in the inventory: vault.yml next to vars.yml, with plaintext aliases
  11. Targeting hosts with patterns, --limit and constructed groups
  12. --limit in practice: every play, run_once per batch, and the facts of hosts left out
  13. Let the inventory be the loop: delegate_to instead of a list of hosts
  14. Several inventories at once: -i dir/, load order, and which source wins
  15. A single source of truth: inventory plugins, enable_plugins and auto
  16. The Foreman/Satellite dynamic inventory plugin
  17. The Proxmox inventory plugin: guests as hosts, filtered by tag and status
  18. ansible.builtin.constructed: keyed_groups, groups and compose on top of another source
  19. When the inventory cache lies: stale hosts, cache_timeout and --flush-cache
  20. The inventory cache and performance: request counts, want_facts and timeouts
  21. add_host: provision then configure in one run
  22. group_by: groups from facts, built during the run
  23. Writing an inventory plugin, after the trust order
  24. Inventory in AAP: sources from a project, smart and constructed inventories
  25. Testing the inventory in CI, with a JSON Schema and policy checks
  26. Local facts in facts.d: declared data that looks measured

Reading order: Running IaC and CaC from a controller

  1. Control node, runner, controller: who runs your Ansible, and how Tower became AWX and AAP
  2. Ansible controllers in 2026: AWX paused, AAP, Semaphore UI, or plain CI
  3. GitOps with tools that push: Ansible and OpenTofu against the four OpenGitOps principles in gitops
  4. OpenTofu in a GitLab pipeline: GitLab-managed state and the OpenTofu CI/CD component in terraform

Everything in this topic, oldest first

Starting an Ansible role project with uv for the venv - 2026-09-05

Ansible needs a Python environment (ansible-core, plus ansible-lint/molecule if you're testing), but a role's directory layout is fixed by ansible-galaxy — not something uv init's project scaffolding understands. So the two tools stay in their own lanes: ansible-galaxy for the…

The Foreman/Satellite dynamic inventory plugin - 2026-09-05

Sixteenth entry in the Ansible inventory from scratch series. Inventory plugins as a single source of truth explained inventory plugins, the auto plugin and the inventory cache in general. This entry applies them to one source: Foreman. Foreman is an open-source server that…

Targeting hosts with patterns, --limit and constructed groups - 2026-09-05

Eleventh entry in the Ansible inventory from scratch series. Item 1 put hosts into groups, and item 5 kept prod and staging in one inventory, where hosts: app runs on both. This entry is about choosing which hosts a command or a play runs on. A host pattern is the expression…

Storing an Ansible Galaxy token as an environment variable, not in ansible.cfg - 2026-09-05

ansible-galaxy needs a token to install from or publish to anything other than the fully public Galaxy — a private Automation Hub, a self-hosted galaxy_ng, or even the public Galaxy for publishing your own collections. The token can live directly in ansible.cfg, but that's…

git tag basics, grounded in how Ansible collection releases actually use them - 2026-09-12

git tag looks simple until a release process actually depends on getting it right. Ansible collection releases are a good concrete example — the tag isn't decorative, tooling reads it back.

Deploying a Podman Quadlet stack on RHEL9 with linux-system-roles - 2026-09-16

Earlier I hand-wrote Quadlet files for Caddy + PHP-FPM directly on the host. The linux-system-roles.podman role turns that into something declarative: instead of writing .container/.network unit files as text, you describe them as nested YAML matching each unit's own [Section]…

Ansible Vault encrypts the secret in git; Podman's default driver stores it in plaintext - 2026-09-20

Encrypting a variable with ansible-vault and rendering it into a Podman secret for a rootless container looks like the secret is protected end to end. It isn't, by default — verified from both the Ansible module's own source and Podman's, because the gap between "encrypted in…

What Ansible Vault actually encrypts, and where that protection stops - 2026-09-24

Ansible's own vault guide opens with a warning worth reading before anything else about the tool: "Encryption with Ansible Vault ONLY protects 'data at rest'." That's a precise boundary, not a vague caveat, and it's worth tracing exactly where it falls — both what "at rest"…

Handling deployment failures with Ansible's block/rescue/always - 2026-09-29

Saw a LinkedIn post comparing Ansible's block/rescue/always to try/catch — deploy, roll back automatically on failure, alert the team, clean up regardless. It's a real, built-in Ansible feature (current docs), and it's more precise than "try/catch" once you look at what…

Locking an Ansible development environment: pip, venv, pip-tools, uv or an execution environment - 2026-09-29

First entry in the Ansible development environment series. An Ansible project needs a runtime on the control node, the machine that runs ansible-playbook. That runtime has five layers, and each tool below fixes some of them:

Pinning ansible-core with pip-tools, uv and Poetry - 2026-09-29

Second entry in the Ansible development environment series; the first ranks all the options. pip-tools, uv and Poetry all do the same job for an Ansible project. They record the exact ansible-core a project runs, plus everything it pulls in, so every laptop and CI job installs…

Building an Ansible execution environment from a locked requirements file - 2026-09-29

Third entry in the Ansible development environment series. An execution environment (EE) is a container image holding the whole Ansible runtime: ansible-core, ansible-runner, Python packages, collections and system packages. The first entry ranks it against the venv-based…

Where to run an Ansible development environment: venv, Dev Container, Remote-SSH, code-server or Dev Spaces - 2026-09-29

Fourth entry in the Ansible development environment series. The first three decide what the runtime is made of and how to lock it. This one decides where the editor and tools run. There are five common answers, and most of the choice comes down to three things:

Ansible Development Tools (ADT): one install, and the Python version decides what you get - 2026-09-29

Fifth entry in the Ansible development environment series. Part 4 chose where the tools run; this one is about the tools themselves. ADT (Ansible Development Tools) is the PyPI package ansible-dev-tools. It's a meta-package: its own code is little more than an adt command, and…

Committing the VS Code Ansible settings with the repository - 2026-09-29

Sixth entry in the Ansible development environment series. Part 4 chose where VS Code runs and part 5 installed the tools. This part makes every developer's editor behave the same way on a given repository. The means is two small files committed next to the code: one for…

Running playbooks locally in the execution environment production uses - 2026-09-30

Seventh entry in the Ansible development environment series. Part 6 pointed the editor at the team's execution environment (EE), the container image that AAP (Red Hat Ansible Automation Platform) and its automation controller run every job in. This part does the same for the…

An Ansible Dev Container: choosing the scaffolded config, Podman, and the EE navigator falls back to - 2026-09-30

Eighth entry in the Ansible development environment series. Part 4 listed the Dev Container as the local, zero-install option, and showed it can run an execution environment (EE) inside it. This part sets one up for real. A Dev Container is a container that VS Code, through…

A shared Ansible dev server for VS Code Remote-SSH, built with Ansible - 2026-09-30

Ninth entry in the Ansible development environment series. Part 4 listed Remote-SSH as the option for shops that only have VMs: VS Code stays on the laptop, and the code, the tools and the execution environments (EEs, the container images that Red Hat Ansible Automation…

Linting Ansible before it reaches Git: `--fix` in the editor, the same ansible-lint in CI - 2026-09-30

Tenth entry in the Ansible development environment series. ansible-lint is the ADT tool that checks playbooks and roles against best-practice rules (part 5). It runs in two places:

Scaffolding with ansible-creator: roles inside a collection, and what to change in the output - 2026-09-30

Eleventh entry in the Ansible development environment series. ansible-creator is the ADT tool (part 5) that generates project layouts, so nobody builds the directories by hand. Alex Dworjan's 2024 videos use an older command syntax. Everything below ran ansible-creator 26.9.0…

A collection-aware venv with ansible-dev-environment (ade): what it installs, what it edits, and how to pin it - 2026-09-30

Twelfth entry in the Ansible development environment series. ansible-dev-environment, whose command is ade, is one of the tools that come with ADT. It builds a venv for Ansible work: a directory with its own Python and packages (part 1 compares it with the other options). Into…

One sudoers line per command with community.general.dict_kv: building a list of dicts from a list of values - 2026-10-01

First entry in the Shaping data in Ansible series. Ansible variables are YAML data: strings, lists and dictionaries (dicts, key–value mappings). Filters are the functions after a | in a {{ }} expression, and they turn one shape of data into another. This entry uses one of them,…

Lists and dicts back and forth: dict2items, items2dict and zip on role, Foreman and Proxmox data - 2026-10-01

Second entry in the Shaping data in Ansible series. Part 1 explains lists, dicts (key–value mappings) and filters (the functions after a |). Data often comes in one of those shapes when the next step needs the other:

Merging dicts with combine: PostgreSQL settings in layers, Quadlet units from a base - 2026-10-01

Third entry in the Shaping data in Ansible series. Part 1 explains dicts (key–value mappings), filters and combine, which merges dicts. There the keys never overlapped. This entry is about what happens when they do:

Picking from a list of dicts: selectattr, rejectattr and map on Proxmox guests and host facts - 2026-10-02

Fourth entry in the Shaping data in Ansible series. Part 1 explains lists, dicts (key–value mappings) and filters (the functions after a |). Much of the data Ansible hands you is a list of dicts: the VMs a module returns, the mounts of a host. This entry is about taking part of…

subelements versus product: Quadlet volume directories and PostgreSQL pg_hba rules - 2026-10-02

Fifth entry in the Shaping data in Ansible series. Two filters pair items so that a single loop or template can go over every combination:

Set operations on lists: declared Proxmox guests against the cluster, and why the order changes between runs - 2026-10-02

Sixth entry in the Shaping data in Ansible series. Drift is the gap between what a configuration declares and what actually exists. Finding it means comparing two lists:

Strings into structures: df with split and regex_findall, findmnt with from_json - 2026-10-02

Seventh entry in the Shaping data in Ansible series. When a task runs a command, register: keeps its output in stdout, one string, and stdout_lines, the same split into lines. Picking values out of it by position, stdout_lines[2].split()[3], breaks as soon as the output changes…

default, default(omit), mandatory and ternary: sudo rules that don't set every field - 2026-10-02

Eighth entry in the Shaping data in Ansible series. Data from people is incomplete: a field left out, left blank, or set to "not decided". In YAML these are three different values:

Forcing types: extra vars arrive as strings, and ansible-core 2.19 stopped guessing - 2026-10-02

Ninth entry in the Shaping data in Ansible series. Extra vars are variables given on the command line with -e (--extra-vars). They override every other variable, which makes them the usual way to flip a switch for one run. But -e name=value always gives a string, whatever the…

Writing data out: a Caddy JSON configuration with to_nice_json, sort_keys and indent - 2026-10-03

Tenth entry in the Shaping data in Ansible series. The earlier parts shaped data inside Ansible. This one writes it out to a file another program reads: part 3's Caddy site, as Caddy's own JSON configuration. Ansible has two filters for each format:

Data from other hosts: pg_hba rules from the app servers' facts, with hostvars and extract - 2026-10-03

Eleventh entry in the Shaping data in Ansible series. Every part so far shaped data that one host already had. A common need goes across hosts: the PostgreSQL server must allow connections from the application servers, so its rules need their addresses. Those addresses are in…

groupby, groupby_as_dict and lists_mergeby: Proxmox guests by node, and joined to what the team declares - 2026-10-03

Twelfth entry in the Shaping data in Ansible series. Part 4 picked items out of a list of dicts, Proxmox VE's guests as community.proxmox.proxmox_vm_info reports them. This entry does two more things with the same list:

json_query or native filters: part 4's Proxmox selections written in JMESPath - 2026-10-03

Thirteenth entry in the Shaping data in Ansible series. Many answers online pick items from Ansible data with json_query, a filter from the community.general collection that runs a JMESPath query. JMESPath is a query language for JSON data, with its own syntax for filtering and…

Network data with ansible.utils: checking pg_hba subnets and numbering Proxmox guests - 2026-10-03

Fourteenth entry in the Shaping data in Ansible series. Addresses and subnets look like strings, but they have rules: 10.30.0.0/33 doesn't exist, and 10.20.0.5/24 is a host address wearing a subnet's prefix. The ansible.utils collection has filters that understand them. This…

set_fact in a loop or one expression: part 11's pg_hba rules, built both ways - 2026-10-03

Fifteenth entry in the Shaping data in Ansible series. Every part so far built data in one expression: a chain of filters in a variable. Many playbooks build it another way, one item at a time: a set_fact task, which sets a variable on the current host, run in a loop, each turn…

Text on lists: building a systemd ExecStart line with regex_replace, join and replace - 2026-10-03

Sixteenth entry in the Shaping data in Ansible series. Part 7 turned text into data. This one goes the other way: it turns a list of options into one line of text, the command a systemd service runs. systemd starts and supervises services on most Linux systems; each service is…

Hosts and groups: the two groups every inventory has, all and ungrouped - 2026-10-03

First entry in the Ansible inventory from scratch series. Ansible runs tasks on remote machines, its managed hosts, from one machine, the controller, where ansible-playbook runs. It finds the hosts in the inventory: a list of host names, sorted into named groups, that a play…

An inventory as a directory: a hosts file without variables, and group_vars per role - 2026-10-03

Second entry in the Ansible inventory from scratch series. Item 1 wrote an inventory, the list of hosts Ansible manages sorted into groups, as a single YAML file, and kept its variables out of it. This entry gives those variables a place: an inventory directory, with a…

INI or YAML for the hosts file, and why variables stay out of both - 2026-10-03

Third entry in the Ansible inventory from scratch series. Item 1 wrote the hosts file, the inventory file that lists hosts and the groups they belong to, in YAML; item 2 moved its variables into group_vars/. Ansible also reads hosts files in INI, the older [section] and…

Connection variables: ansible_host, ansible_port, ansible_user and ansible_connection, with ssh, docker and local - 2026-10-03

Fourth entry in the Ansible inventory from scratch series. The inventory so far, from item 1 to item 3, named hosts and groups and connected to all of them on the local machine. This entry reaches three hosts three different ways, and looks at the four variables that decide…

Environments in an Ansible inventory: separate directories, or prod and staging as groups - 2026-10-03

Fifth entry in the Ansible inventory from scratch series. Item 2 turned the inventory into a directory, with a hosts file and group_vars/, and item 4 told Ansible how to reach each host. Most real setups have the same stack more than once: an environment is one complete copy of…

Checking what Ansible sees: ansible-inventory --graph, --list and --host - 2026-10-03

Sixth entry in the Ansible inventory from scratch series. Items 1 to 4 built an inventory, the list of hosts Ansible manages sorted into groups, with its variables in group_vars/ directories. This entry breaks it on purpose, three ways, and finds each mistake with…

Facts or variables: what Ansible discovers (as-is) against what you declare (to-be) - 2026-10-03

Seventh entry in the Ansible inventory from scratch series. The entries so far put variables in the inventory: item 2 in group_vars/, item 4 connection settings in host_vars/. Ansible also learns things about each host by itself, its facts. This entry looks at the difference…

Where a variable should live: role defaults, group_vars, host_vars, and extra vars as safety switches - 2026-10-03

Eighth entry in the Ansible inventory from scratch series. Item 2 gave variables a place in the inventory, and item 7 kept discovered facts out of it. Ansible accepts variables in 22 places, though, ranked by precedence: when two places set the same name, the higher one wins.…

Inventory precedence: all, parent, child, host, and what ansible_group_priority really does - 2026-10-03

Ninth entry in the Ansible inventory from scratch series. Item 8 ranked the places a variable can live, with the inventory's group_vars/ and host_vars/ as the home of desired state. Inside the inventory, the same name can still be set for all, for several groups a host belongs…

Secrets in the inventory: vault.yml next to vars.yml, with plaintext aliases - 2026-10-03

Tenth entry in the Ansible inventory from scratch series. Item 8 put desired state in the inventory's group_vars/ and host_vars/, and some of that state is secret: a database password, an API token. Ansible Vault encrypts it so the repository holds ciphertext, decrypted at run…

--limit in practice: every play, run_once per batch, and the facts of hosts left out - 2026-10-03

Twelfth entry in the Ansible inventory from scratch series. Item 11 covered host patterns, the expressions that choose hosts, and --limit, the option that keeps only the hosts of a run that also match another pattern. This entry is about what --limit does beyond choosing hosts:…

Let the inventory be the loop: delegate_to instead of a list of hosts - 2026-10-03

Thirteenth entry in the Ansible inventory from scratch series. Item 12 showed what --limit does to a run. This entry is about a layout that --limit can't reach: a list of hosts kept in a variable, looped over by a task. The Red Hat Community of Practice's automation good…

Several inventories at once: -i dir/, load order, and which source wins - 2026-10-03

Fourteenth entry in the Ansible inventory from scratch series. Item 2 turned the inventory into a directory, and item 11 put a second YAML file and a constructed source in it, merged into one set of hosts before any pattern applies. This entry is about what happens when those…

A single source of truth: inventory plugins, enable_plugins and auto - 2026-10-03

Fifteenth entry in the Ansible inventory from scratch series. The earlier items wrote every host by hand, in a hosts file with group_vars/ and host_vars/. In most companies, though, the list of servers already lives somewhere else. The Red Hat Community of Practice's automation…

The Proxmox inventory plugin: guests as hosts, filtered by tag and status - 2026-10-03

Seventeenth entry in the Ansible inventory from scratch series. Item 13 made the VMs hosts of the inventory instead of a list in a variable, but wrote them by hand. When the VMs already exist on a hypervisor, the hypervisor is the place that knows them, and a dynamic inventory…

ansible.builtin.constructed: keyed_groups, groups and compose on top of another source - 2026-10-03

Eighteenth entry in the Ansible inventory from scratch series. The previous entry turned the guests of a Proxmox VE cluster into hosts with the community.proxmox.proxmox inventory plugin. Its groups follow Proxmox's own layout: one per node, per guest type, per status and per…

When the inventory cache lies: stale hosts, cache_timeout and --flush-cache - 2026-10-03

Nineteenth entry in the Ansible inventory from scratch series. Item 15 read hosts from a mock CMDB (Configuration Management Database, where an IT department records its servers) with a small inventory plugin of the example's own, and turned on its inventory cache: the plugin…

The inventory cache and performance: request counts, want_facts and timeouts - 2026-10-03

Twentieth entry in the Ansible inventory from scratch series. The previous entry, When the inventory cache lies, was about the cost of the inventory cache: an inventory plugin that keeps what it read from its source and answers from that copy on later runs can hand Ansible…

add_host: provision then configure in one run - 2026-10-03

Twenty-first entry in the Ansible inventory from scratch series. Item 13 provisioned VMs through a fake manager, with the VMs already listed in the inventory. This entry takes the case where they aren't: the VMs get their names and addresses only when the manager creates them,…

group_by: groups from facts, built during the run - 2026-10-03

Twenty-second entry in the Ansible inventory from scratch series. The earlier items gave each group a place in the inventory before the run: in a hosts file, or built by an inventory plugin from the data of another system. Some groups depend on what a host turns out to be: its…

Writing an inventory plugin, after the trust order - 2026-10-03

Twenty-third entry in the Ansible inventory from scratch series. Item 15 read a mock CMDB (a Configuration Management Database, where an IT department records its servers) with a static copy, an inventory script and a 70-line inventory plugin, and called that plugin an…

Inventory in AAP: sources from a project, smart and constructed inventories - 2026-10-03

Twenty-fourth entry in the Ansible inventory from scratch series. The earlier items ran everything with ansible-core on the command line. Many teams run their playbooks from Ansible Automation Platform (AAP) instead, Red Hat's product whose web interface and API, the automation…

Testing the inventory in CI, with a JSON Schema and policy checks - 2026-10-03

Twenty-fifth entry, and the last, in the Ansible inventory from scratch series. Item 6 used ansible-inventory to look at what Ansible sees, by hand. This entry makes that look automatic: a test that runs on every change to the inventory and fails when a variable is missing, has…

Local facts in facts.d: declared data that looks measured - 2026-10-04

Twenty-sixth entry in the Ansible inventory from scratch series, a follow-up to item 7. Item 7 split what a host is (as-is, discovered as facts) from what it should be (to-be, declared in the inventory), and compared the two to find drift. Ansible has a way to hand a host extra…

A playbook hangs at fact gathering or `service_facts`: find the blocking call, then bound it - 2026-10-17

The play prints TASK [Gathering Facts] or TASK [ansible.builtin.service_facts] and nothing else, for hours. Ansible has no timeout on a task by default, so one command that never returns on one host holds up the whole run.

Control node, runner, controller: who runs your Ansible, and how Tower became AWX and AAP - 2026-10-22

First entry in the Running IaC and CaC from a controller series. Infrastructure as code (IaC) means describing servers, networks and their configuration in files kept in Git, and letting a tool apply them: Ansible for configuration, Terraform/OpenTofu for provisioning, Packer…

Ansible controllers in 2026: AWX paused, AAP, Semaphore UI, or plain CI - 2026-10-22

Second entry in the Running IaC and CaC from a controller series. The first entry separated the three roles: the control node runs ansible-playbook; a runner runs CI jobs; a controller is a service that stores projects, inventories, credentials and templates, launches runs and…