What is the `constructed` inventory plugin?
AdvancedConceptInventory
Answer
ansible.builtin.constructed builds extra groups and variables from the hosts discovered by other inventory sources, using Jinja2 conditions and host variables. It is placed in the same inventory directory and runs after the other sources.
# inventory/zz_constructed.yml
plugin: ansible.builtin.constructed
strict: false
groups:
prod_web: "env == 'prod' and 'web' in role"
keyed_groups:
- key: ansible_facts.distribution
prefix: os
compose:
deploy_dir: "'/opt/' ~ app_name"
It lets one team own the cloud inventory while another layers logical grouping on top, without editing the plugin config.
More on Inventory
What is an inventory and why does Ansible need one?BeginnerWhat are the INI and YAML inventory formats and how do they differ?BeginnerHow do you create groups of groups?BeginnerExplain host patterns: `:`, `:&`, `:!` and wildcards.IntermediateWhich connection variables can you set per host in inventory?BeginnerWhat are `group_vars` and `host_vars` directories?Intermediate