Search code examples
jenkinsansibleansible-tower

Ansible Tower CLI pass Launch Parameters in one command without prompt


I am trying to launch an ansible-tower cli job through Jenkins. But I don't want a prompt that appears on Ansible Tower. I want to pass those parameters in the same command so that a prompt is not required.

I have tried:

tower-cli job launch --job-template=33 -e "param1" -e "param2"

This is the error I get:

Error: failed to pass some of the extra variables


Solution

  • According to the Ansible Tower-CLI documentation the parameter -e is wrong. You need to use --extra-vars. This differs from ansible-playbook command. So an easy example is

    tower-cli job launch --job-template 1 --extra-vars '{"x":"y"}'
    

    Be aware that you write all vars in one argument. The --extra-vars expects JSON or YAML format.

    Be also aware, that the given job template MUST be configured to ask for extra-vars. Otherwise the argument is ignored on Ansible Tower side.

    Also - not the question but a good advice - if your Jenkins needs to wait for the job result add --monitor to the tower-cli command. Then the cli waits for the response code and the stage could "fail" if there is a problem.