summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/inventory_advanced_host_list/runme.sh
blob: 41b1f8b9530f4cb2e0ec8328e3b4b52166331316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash

set -eux

export ANSIBLE_INVENTORY_ENABLED=advanced_host_list

# A few things to make it easier to grep against adhoc
export ANSIBLE_LOAD_CALLBACK_PLUGINS=True
export ANSIBLE_STDOUT_CALLBACK=oneline

adhoc="$(ansible -i 'local[0:10],' -m ping --connection=local -e ansible_python_interpreter="{{ ansible_playbook_python }}" all -v)"

for i in $(seq 0 10); do
    grep -qE "local${i} \| SUCCESS.*\"ping\": \"pong\"" <<< "$adhoc"
done

set +e
parse_fail="$(ansible -i 'local[1:j],' -m ping --connection=local all -v 2>&1)"
set -e

grep -q "Failed to parse local\[1:j\], with advanced_host_list" <<< "$parse_fail"

# Intentionally missing comma, ensure we don't fatal.
no_comma="$(ansible -i 'local[1:5]' -m ping --connection=local all -v 2>&1)"
grep -q "No inventory was parsed" <<< "$no_comma"

# Intentionally botched range (missing end number), ensure we don't fatal.
no_end="$(ansible -i 'local[1:],' -m ping --connection=local -e ansible_python_interpreter="{{ ansible_playbook_python }}" all -vvv 2>&1)"
grep -q "Unable to parse address from hostname, leaving unchanged:" <<< "$no_end"
grep -q "host range must specify end value" <<< "$no_end"
grep -q "local\[3:\] \| SUCCESS" <<< "$no_end"

# Unset adhoc stuff
unset ANSIBLE_LOAD_CALLBACK_PLUGINS ANSIBLE_STDOUT_CALLBACK

ansible-playbook -i 'local100,local[100:110:2]' test_advanced_host_list.yml -v "$@"