summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/hosts_field/runme.sh
blob: 1291933c5bbe6ee15a6af8a342b379b6a60dd3ea (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
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash

set -eux

# Hosts in playbook has a list of strings consisting solely of digits
ansible-playbook test_hosts_field.yml -i inventory.hosts_field -e 'target_kv=42' \
    -e '{ "target_json_cli": "42", "target_json_cli_list": ["42", "localhost"] }' -e "@test_hosts_field.json" \
    -t string_digit_host_in_list -v "$@" | tee test_hosts_field.out
grep 'Running on 42' test_hosts_field.out 2>&1
test "$(grep -c 'ok=1' test_hosts_field.out)" = 1

# Hosts taken from kv extra_var on the CLI
ansible-playbook test_hosts_field.yml -i inventory.hosts_field -e 'target_kv=42' \
    -e '{ "target_json_cli": "42", "target_json_cli_list": ["42", "localhost"] }' -e "@test_hosts_field.json" \
    -t hosts_from_kv_string -v "$@" | tee test_hosts_field.out
grep 'Running on 42' test_hosts_field.out 2>&1
test "$(grep -c 'ok=1' test_hosts_field.out)" = 1

# hosts is taken from an all digit json extra_vars string on the CLI
ansible-playbook test_hosts_field.yml -i inventory.hosts_field -e 'target_kv=42' \
    -e '{ "target_json_cli": "42", "target_json_cli_list": ["42", "localhost"] }' -e "@test_hosts_field.json" \
    -t hosts_from_cli_json_string -v "$@" | tee test_hosts_field.out
grep 'Running on 42' test_hosts_field.out 2>&1
test "$(grep -c 'ok=1' test_hosts_field.out)" = 1

# hosts is taken from a json list in extra_vars on the CLI
ansible-playbook test_hosts_field.yml -i inventory.hosts_field -e 'target_kv=42' \
    -e '{ "target_json_cli": "42", "target_json_cli_list": ["42", "localhost"] }' -e "@test_hosts_field.json" \
    -t hosts_from_cli_json_list -v "$@" | tee test_hosts_field.out
grep 'Running on 42' test_hosts_field.out 2>&1
grep 'Running on localhost' test_hosts_field.out 2>&1
test "$(grep -c 'ok=1' test_hosts_field.out)" = 2

# hosts is taken from a json string in an extra_vars file
ansible-playbook test_hosts_field.yml -i inventory.hosts_field -e 'target_kv=42' \
    -e '{ "target_json_cli": "42", "target_json_cli_list": ["42", "localhost"] }' -e "@test_hosts_field.json" \
    -t hosts_from_json_file_string -v "$@" | tee test_hosts_field.out
grep 'Running on 42' test_hosts_field.out 2>&1
test "$(grep -c 'ok=1' test_hosts_field.out)" = 1

# hosts is taken from a json list in an extra_vars file
ansible-playbook test_hosts_field.yml -i inventory.hosts_field -e 'target_kv=42' \
    -e '{ "target_json_cli": "42", "target_json_cli_list": ["42", "localhost"] }' -e "@test_hosts_field.json" \
    -t hosts_from_json_file_list -v "$@" | tee test_hosts_field.out
grep 'Running on 42' test_hosts_field.out 2>&1
grep 'Running on localhost' test_hosts_field.out 2>&1
test "$(grep -c 'ok=1' test_hosts_field.out)" = 2

rm test_hosts_field.out