We have recently built an API that allows us to query a list of VM's rather than using an inventory file. I am trying to incorporate this with our ansible set-up. I am very new to using a dynamic inventory and have tried a few different variations with bash since I am not very experienced with python.
This almost works but as long as the playbook does not have become:true. If the playbook requires sudo I get this error
FAILED! => {"changed": false, "module_stderr": "/bin/sh: sudo: command not found", "module_stdout": "", "msg": "MODULE FAILURE", "rc": 127}
SERVER1=($(curl -sS --request GET https://foo/bar| awk 'BEGIN {FS="["} {print $1}'))
cat <<EOF
{
"test1": {
"hosts": ["$SERVER1"],
}
}
EOF
I have tried to find examples of what I am trying to do but have been coming up short.
I have 3 groups I need to run a play on (test1,test2,test3) This is the closest I have gotten it to work. If doing this with python is easier or the preferred method I could work to figure it out I just can't tell at this point if i'm close to a solution or way off. Any help is appreciated.
SERVER1=($(curl -sS --request GET https://foo/bar| awk 'BEGIN {FS="["} {print $1}'))
SERVER2=($(curl -sS --request GET https://foo/bar| awk 'BEGIN {FS="["} {print $2}'))
SERVER3=($(curl -sS --request GET https://foo/bar| awk 'BEGIN {FS="["} {print $3}'))
cat <<EOF
{
"test1": {
"hosts": ["$SERVER1"],
},
"test2": {
"hosts": ["$SERVER2"],
},
"test3": {
"hosts": ["$SERVER3"],
}
}
EOF