Revert "generator: add support for extra vars usage (#84544)" (#84619)

This reverts commit 186c716af1.
pull/84641/head
Matt Clay 11 months ago committed by GitHub
parent e6adddcaf8
commit ce392dd86e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -1,3 +0,0 @@
---
minor_changes:
- generator - add support for extra vars (https://github.com/ansible/ansible/issues/83270).

@ -32,20 +32,6 @@ DOCUMENTATION = """
description:
- A dictionary of layers, with the key being the layer name, used as a variable name in the C(host)
C(name) and C(parents) keys. Each layer value is a list of possible values for that layer.
use_extra_vars:
version_added: '2.19'
description:
- Merge extra vars into the available variables for composition (highest precedence).
type: bool
default: false
ini:
- section: inventory_plugins
key: use_extra_vars
- section: inventory_plugin_generator
key: use_extra_vars
env:
- name: ANSIBLE_INVENTORY_USE_EXTRA_VARS
- name: ANSIBLE_GENERATOR_USE_EXTRA_VARS
"""
EXAMPLES = """
@ -91,7 +77,6 @@ from itertools import product
from ansible import constants as C
from ansible.errors import AnsibleParserError
from ansible.plugins.inventory import BaseInventoryPlugin
from ansible.utils.vars import load_extra_vars
class InventoryModule(BaseInventoryPlugin):
@ -138,14 +123,10 @@ class InventoryModule(BaseInventoryPlugin):
super(InventoryModule, self).parse(inventory, loader, path, cache=cache)
config = self._read_config_data(path)
if self.get_option('use_extra_vars'):
extra_vars = load_extra_vars(loader)
else:
extra_vars = {}
template_inputs = product(*config['layers'].values())
for item in template_inputs:
template_vars = dict()
template_vars.update(extra_vars)
for i, key in enumerate(config['layers'].keys()):
template_vars[key] = item[i]
host = self.template(config['hosts']['name'], template_vars)

@ -1,8 +0,0 @@
plugin: ansible.builtin.generator
use_extra_vars: True
hosts:
name: "{{ region }}_{{ machine_type }}"
layers:
machine_type:
- web
- db

@ -1,10 +0,0 @@
plugin: ansible.builtin.generator
hosts:
name: "{{ region }}_{{ machine_type }}"
layers:
machine_type:
- web
- db
region:
- mumbai
- pune

@ -1,18 +0,0 @@
plugin: ansible.builtin.generator
hosts:
name: "{{ application }}_{{ operation }}_runner"
parents:
- name: "{{ environment }}"
vars:
log: "s"
layers:
operation:
- build
- launch
environment:
- dev
- test
- prod
application:
- web
- api

@ -1,25 +0,0 @@
#!/usr/bin/env bash
set -eux
ansible-inventory -i generator.yml --graph | tee out.txt
grep 'mumbai_web' out.txt
grep 'mumbai_db' out.txt
grep 'pune_web' out.txt
grep 'pune_db' out.txt
ANSIBLE_INVENTORY_USE_EXTRA_VARS=True ansible-inventory -i extra_vars_generator.yml --graph -e "region=pune"
grep 'pune_web' out.txt
grep 'pune_db' out.txt
ansible-inventory -i generator_parent.yml --graph | tee out.txt
grep 'web_build_runner' out.txt
grep 'api_build_runner' out.txt
grep 'web_launch_runner' out.txt
grep 'api_launch_runner' out.txt
grep '@dev' out.txt
grep '@test' out.txt
grep '@prod' out.txt
Loading…
Cancel
Save