I am using a script module to run a script on some hosts. I have an array ansible variable, that I want to pass the script as space separated arguments. Passing the array variable directly as argument does not help. Suggestions ?
1 Answer
You can join your list with jinja filter and pass it as a variable, like this:
ansible -m script -a "myscript.sh {{ test_list|join(' ') }}" localhost -e "{"test_list": [1,2,3]}"
If myscript.sh is:
#!/bin/bash
echo Args are: ${@}, 1st: $1 2nd: $2, 3d: $3
The output will be:
localhost | SUCCESS => {
"changed": true,
"failed": false,
"rc": 0,
"stderr": "",
"stdout": "Args are: 1 2 3, 1st: 1 2nd: 2, 3d: 3\n",
"stdout_lines": [
"Args are: 1 2 3, 1st: 1 2nd: 2, 3d: 3"
]
}