Debian Codegraph @

test/integration/targets/playbook/runme.sh

raw
1 #!/usr/bin/env bash
2
3 set -eux
4
5 # run type tests
6 ansible-playbook -i ../../inventory types.yml -v "$@"
7
8 # test timeout
9 ansible-playbook -i ../../inventory timeout.yml -v "$@"
10
11 # our Play class allows for 'user' or 'remote_user', but not both.
12 # first test that both user and remote_user work individually
13 set +e
14 result="$(ansible-playbook -i ../../inventory user.yml -v "$@" 2>&1)"
15 set -e
16 grep -q "worked with user" <<< "$result"
17 grep -q "worked with remote_user" <<< "$result"
18
19 # then test that the play errors if user and remote_user both exist
20 echo "EXPECTED ERROR: Ensure we fail properly if a play has both user and remote_user."
21 set +e
22 result="$(ansible-playbook -i ../../inventory remote_user_and_user.yml -v "$@" 2>&1)"
23 set -e
24 grep -q "both 'user' and 'remote_user' are set for this play." <<< "$result"
25
26 # test that playbook errors if len(plays) == 0
27 echo "EXPECTED ERROR: Ensure we fail properly if a playbook is an empty list."
28 set +e
29 result="$(ansible-playbook -i ../../inventory empty.yml -v "$@" 2>&1)"
30 set -e
31 grep -q "A playbook must contain at least one play" <<< "$result"
32
33 # test that play errors if len(hosts) == 0
34 echo "EXPECTED ERROR: Ensure we fail properly if a play has 0 hosts."
35 set +e
36 result="$(ansible-playbook -i ../../inventory empty_hosts.yml -v "$@" 2>&1)"
37 set -e
38 grep -q "Hosts list cannot be empty. Please check your playbook" <<< "$result"
39
40 # test that play errors if tasks is malformed
41 echo "EXPECTED ERROR: Ensure we fail properly if tasks is malformed."
42 set +e
43 result="$(ansible-playbook -i ../../inventory malformed_tasks.yml -v "$@" 2>&1)"
44 set -e
45 grep -q "A malformed block was encountered while loading tasks: 123 should be a list or None" <<< "$result"
46
47 # test that play errors if pre_tasks is malformed
48 echo "EXPECTED ERROR: Ensure we fail properly if pre_tasks is malformed."
49 set +e
50 result="$(ansible-playbook -i ../../inventory malformed_pre_tasks.yml -v "$@" 2>&1)"
51 set -e
52 grep -q "A malformed block was encountered while loading pre_tasks" <<< "$result"
53
54 # test that play errors if post_tasks is malformed
55 echo "EXPECTED ERROR: Ensure we fail properly if post_tasks is malformed."
56 set +e
57 result="$(ansible-playbook -i ../../inventory malformed_post_tasks.yml -v "$@" 2>&1)"
58 set -e
59 grep -q "A malformed block was encountered while loading post_tasks" <<< "$result"
60
61 # test roles: null -- it gets converted to [] internally
62 ansible-playbook -i ../../inventory roles_null.yml -v "$@"
63
64 # test roles: 123 -- errors
65 echo "EXPECTED ERROR: Ensure we fail properly if roles is malformed."
66 set +e
67 result="$(ansible-playbook -i ../../inventory malformed_roles.yml -v "$@" 2>&1)"
68 set -e
69 grep -q "A malformed role declaration was encountered." <<< "$result"
70
71 # test roles: ["foo,bar"] -- errors about old style
72 echo "EXPECTED ERROR: Ensure we fail properly if old style role is given."
73 set +e
74 result="$(ansible-playbook -i ../../inventory old_style_role.yml -v "$@" 2>&1)"
75 set -e
76 grep -q "Invalid old style role requirement: foo,bar" <<< "$result"
77
78 # test vars prompt that has no name
79 echo "EXPECTED ERROR: Ensure we fail properly if vars_prompt has no name."
80 set +e
81 result="$(ansible-playbook -i ../../inventory malformed_vars_prompt.yml -v "$@" 2>&1)"
82 set -e
83 grep -q "Invalid vars_prompt data structure, missing 'name' key" <<< "$result"
84
85 # test vars_prompt: null
86 ansible-playbook -i ../../inventory vars_prompt_null.yml -v "$@"
87
88 # test vars_files: null
89 ansible-playbook -i ../../inventory vars_files_null.yml -v "$@"
90
91 # test vars_files: filename.yml
92 ansible-playbook -i ../../inventory vars_files_string.yml -v "$@"