Debian Codegraph @

test/integration/targets/cache-plugins/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux
4
5 # Test Fact Caching
6
7 export ANSIBLE_CACHE_PLUGIN="dummy_cache"
8
9 # test set_fact with cacheable: true
10 ansible-playbook test_fact_gathering.yml --tags set_fact "$@"
11 ansible-playbook inspect_cache.yml --tags set_fact "$@"
12
13 # cache gathered facts in addition
14 ansible-playbook test_fact_gathering.yml --tags gather_facts "$@"
15 ansible-playbook inspect_cache.yml --tags additive_gather_facts "$@"
16
17 # flush cache and only cache gathered facts
18 ansible-playbook test_fact_gathering.yml --flush-cache --tags gather_facts --tags flush "$@"
19 ansible-playbook inspect_cache.yml --tags gather_facts "$@"
20
21 unset ANSIBLE_CACHE_PLUGIN
22
23 # Test Inventory Caching
24
25 export ANSIBLE_INVENTORY_CACHE=true
26 export ANSIBLE_INVENTORY_CACHE_PLUGIN=dummy_cache
27
28 # Legacy cache plugins need to be updated to use set_options/get_option to be compatible with inventory plugins.
29 # Inventory plugins load cache options with the config manager.
30 ansible-playbook test_inventory_cache.yml "$@"
31
32 ansible-playbook inspect_inventory_cache.yml -i test.inventoryconfig.yml "$@"
33
34 # test file based cache with 'fun' inventory names
35 export ANSIBLE_CACHE_PLUGIN=dummy_file_cache ANSIBLE_CACHE_PLUGIN_CONNECTION="${OUTPUT_DIR}/dummy-file-cache"
36 mkdir -p "${ANSIBLE_CACHE_PLUGIN_CONNECTION}"
37 ansible-playbook -i chroot_inventory_config.yml invalid_hostname_file_caches.yml "$@"
38
39 # same, but using 'persistent' route
40 ANSIBLE_CACHE_PLUGIN=dummy_file_cache_persistent ansible-playbook -i chroot_inventory_config.yml invalid_hostname_file_caches.yml "$@"
41
42 # test file based cache with 'fun' inventory names, and a prefix!
43 export ANSIBLE_CACHE_PLUGIN_PREFIX="YOLO"
44 ansible-playbook -i chroot_inventory_config.yml invalid_hostname_file_caches.yml "$@"
45
46 ANSIBLE_CACHE_PLUGIN=dummy_file_cache_persistent ansible-playbook -i chroot_inventory_config.yml invalid_hostname_file_caches.yml "$@"
47
48 # test user-facing jsonfile 'persistent' route specifically, which relies on internal implementation details
49 export ANSIBLE_CACHE_PLUGIN=ansible.builtin.jsonfile \
50 ANSIBLE_CACHE_PLUGIN_CONNECTION="${OUTPUT_DIR}" \
51 ANSIBLE_CACHE_PLUGIN_PREFIX=legacy_ \
52 ANSIBLE_CACHE_JSONFILE_PERSIST_METADATA=false
53
54 ansible localhost -m assert -a "that='TEST_FACT is undefined'"
55 ansible localhost -m set_fact -a "cacheable='True' TEST_FACT='DEFINED'"
56 ansible localhost -m assert -a "that='TEST_FACT is defined'"
57
58 if [[ ! -f "$OUTPUT_DIR/legacy_localhost" ]]; then
59 echo "Missing expected cache filename"
60 exit 1
61 elif ! grep -q "${OUTPUT_DIR}/legacy_localhost" -e '{"TEST_FACT": "DEFINED"}'; then
62 echo "Missing expected cache format"
63 exit 1
64 fi