Debian Codegraph @

test/integration/targets/old_style_vars_plugins/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux
4
5 export ANSIBLE_VARS_PLUGINS=./vars_plugins
6
7 # Test vars plugin without REQUIRES_ENABLED class attr and vars plugin with REQUIRES_ENABLED = False run by default
8 [ "$(ansible-inventory -i localhost, --list --yaml all "$@" | grep -Ec '(implicitly|explicitly)_auto_enabled')" = "2" ]
9
10 # Test vars plugin with REQUIRES_ENABLED=True only runs when enabled
11 [ "$(ansible-inventory -i localhost, --list --yaml all "$@" | grep -Ec 'require_enabled')" = "0" ]
12 export ANSIBLE_VARS_ENABLED=require_enabled
13 [ "$(ansible-inventory -i localhost, --list --yaml all "$@" | grep -c 'require_enabled')" = "1" ]
14
15 # Test how many times vars plugins are loaded for a simple play containing a task
16 # host_group_vars is stateless, so we can load it once and reuse it, every other vars plugin should be instantiated before it runs
17 cat << EOF > "test_task_vars.yml"
18 ---
19 - hosts: localhost
20 connection: local
21 gather_facts: no
22 tasks:
23 - debug:
24 EOF
25
26 # hide the debug noise by dumping to a file
27 trap 'rm -rf -- "out.txt"' EXIT
28
29 ANSIBLE_DEBUG=True ansible-playbook test_task_vars.yml > out.txt
30 [ "$(grep -c "Loading VarsModule 'host_group_vars'" out.txt)" -eq 1 ]
31 [ "$(grep -c "Loading VarsModule 'require_enabled'" out.txt)" -eq 22 ]
32 [ "$(grep -c "Loading VarsModule 'auto_enabled'" out.txt)" -eq 22 ]
33
34 export ANSIBLE_VARS_ENABLED=ansible.builtin.host_group_vars
35 ANSIBLE_DEBUG=True ansible-playbook test_task_vars.yml > out.txt
36 [ "$(grep -c "Loading VarsModule 'host_group_vars'" out.txt)" -eq 1 ]
37 [ "$(grep -c "Loading VarsModule 'require_enabled'" out.txt)" -lt 3 ]
38 [ "$(grep -c "Loading VarsModule 'auto_enabled'" out.txt)" -eq 22 ]
39
40 ansible localhost -m include_role -a 'name=a' "$@"