Debian Codegraph @

test/integration/targets/ansible/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux -o pipefail
4
5 ansible --version
6 ansible --help
7
8 ansible testhost -i ../../inventory -m ping "$@"
9 ansible testhost -i ../../inventory -m setup "$@"
10
11 ansible-config view -c ./ansible-testé.cfg | grep 'remote_user = admin'
12 ansible-config dump -c ./ansible-testé.cfg | grep 'DEFAULT_REMOTE_USER([^)]*) = admin\>'
13 ANSIBLE_REMOTE_USER=administrator ansible-config dump| grep 'DEFAULT_REMOTE_USER([^)]*) = administrator\>'
14 ansible-config list | grep 'DEFAULT_REMOTE_USER'
15
16 # Collection
17 ansible-config view -c ./ansible-testé.cfg | grep 'collections_path = /tmp/collections'
18 ansible-config dump -c ./ansible-testé.cfg | grep 'COLLECTIONS_PATHS([^)]*) ='
19 ANSIBLE_COLLECTIONS_PATH=/tmp/collections ansible-config dump| grep 'COLLECTIONS_PATHS([^)]*) ='
20 ansible-config list | grep 'COLLECTIONS_PATHS'
21
22 # 'view' command must fail when config file is missing or has an invalid file extension
23 ansible-config view -c ./ansible-non-existent.cfg 2> err1.txt || grep -Eq 'The provided configuration file is missing or not accessible:' err1.txt || (cat err*.txt; rm -f err1.txt; exit 1)
24 ansible-config view -c ./no-extension 2> err2.txt || grep -q 'Unsupported configuration file extension' err2.txt || (cat err2.txt; rm -f err*.txt; exit 1)
25 rm -f err*.txt
26
27 # test setting playbook_dir via envvar
28 ANSIBLE_PLAYBOOK_DIR=/doesnotexist/tmp ansible localhost -m debug -a var=playbook_dir | grep '"playbook_dir": "/doesnotexist/tmp"'
29
30 # test setting playbook_dir via cmdline
31 ansible localhost -m debug -a var=playbook_dir --playbook-dir=/doesnotexist/tmp | grep '"playbook_dir": "/doesnotexist/tmp"'
32
33 # test setting playbook dir via ansible.cfg
34 env -u ANSIBLE_PLAYBOOK_DIR ANSIBLE_CONFIG=./playbookdir_cfg.ini ansible localhost -m debug -a var=playbook_dir | grep '"playbook_dir": "/doesnotexist/tmp"'
35
36 # test adhoc callback triggers
37 ANSIBLE_CALLBACK_PLUGINS=../support-callback_plugins/callback_plugins ANSIBLE_STDOUT_CALLBACK=callback_debug ANSIBLE_LOAD_CALLBACK_PLUGINS=1 ansible --playbook-dir . testhost -i ../../inventory -m ping | grep -E '^v2_' | diff -u adhoc-callback.stdout -
38
39 # CB_WANTS_IMPLICIT isn't anything in Ansible itself.
40 # Our test cb plugin just accepts it. It lets us avoid copypasting the whole
41 # plugin just for two tests.
42 CB_WANTS_IMPLICIT=1 ANSIBLE_STDOUT_CALLBACK=callback_meta ANSIBLE_LOAD_CALLBACK_PLUGINS=1 ansible-playbook -i ../../inventory --extra-vars @./vars.yml playbook.yml | grep 'saw implicit task'
43
44 set +e
45 if ANSIBLE_STDOUT_CALLBACK=callback_meta ANSIBLE_LOAD_CALLBACK_PLUGINS=1 ansible-playbook -i ../../inventory --extra-vars @./vars.yml playbook.yml | grep 'saw implicit task'; then
46 echo "Callback got implicit task and should not have"
47 exit 1
48 fi
49 set -e
50
51 # Test that no tmp dirs are left behind when running ansible-config
52 TMP_DIR=~/.ansible/tmptest
53 if [[ -d "$TMP_DIR" ]]; then
54 rm -rf "$TMP_DIR"
55 fi
56 ANSIBLE_LOCAL_TEMP="$TMP_DIR" ansible-config list > /dev/null
57 ANSIBLE_LOCAL_TEMP="$TMP_DIR" ansible-config dump > /dev/null
58 ANSIBLE_LOCAL_TEMP="$TMP_DIR" ansible-config view > /dev/null
59
60 # wc on macOS is dumb and returns leading spaces
61 file_count=$(find "$TMP_DIR" -type d -maxdepth 1 | wc -l | sed 's/^ *//')
62 if [[ $file_count -ne 1 ]]; then
63 echo "$file_count temporary files were left behind by ansible-config"
64 if [[ -d "$TMP_DIR" ]]; then
65 rm -rf "$TMP_DIR"
66 fi
67 exit 1
68 fi
69
70 # Ensure extra vars filename is prepended with '@' sign
71 if ansible-playbook -i ../../inventory --extra-vars /tmp/non-existing-file playbook.yml; then
72 echo "extra_vars filename without '@' sign should cause failure"
73 exit 1
74 fi
75
76 # Ensure extra vars filename is prepended with '@' sign
77 if ansible-playbook -i ../../inventory --extra-vars ./vars.yml playbook.yml; then
78 echo "extra_vars filename without '@' sign should cause failure"
79 exit 1
80 fi
81
82 ansible-playbook -i ../../inventory --extra-vars @./vars.yml playbook.yml
83
84 # #74270 -- ensure we escape directory names before passing to re.compile()
85 # particularly in module_common.
86 bash module_common_regex_regression.sh