0

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 1

1

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"
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.