blob: 119305deff3cadf65ccc4e76fd4eccdb1e817640 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
## this contains several helper functions
get_ansible_variable() {
local _var_name="$1"
local _hosts="$2"
local _result=$(env ANSIBLE_STDOUT_CALLBACK="json" ansible "$_hosts" -m debug -a "var=$_var_name" | \
jq -r ".plays[].tasks[].hosts[].$_var_name" | sort | uniq)
if [ $? -ne 0 ] || [ -z "$_result" ]; then
return 1
fi
local _num_results=$(echo "$_result" | wc -l)
if [ $_num_results -ne 1 ]; then
echo "ERROR: the vairable '$_var_name' is not unique for the given hosts '$_hosts', got values: $(echo $_result | xargs | sed 's/ /, /g')"
return 2
fi
eval "$_var_name"='$(echo "$_result")'
return 0
}
|