0

I want to launch a Job-Template via the AWX-API including some extra_vars, but every response I get has an empty extra_vars field. I already checked the documentation about it: https://docs.ansible.com/ansible-tower/latest/html/userguide/job_templates.html#extra-variables

which states, that you have to set ask_variables_on_launch: true and/or have corresponding variables in a survey. My Request checks both of these conditions:

Request

 POST: https://my.awx.host/api/v2/job_templates/7/launch/

Body

 {
"can_start_without_user_input": false,
"passwords_needed_to_start": [],
"ask_scm_branch_on_launch": false,
"ask_variables_on_launch": true,
"ask_tags_on_launch": false,
"ask_diff_mode_on_launch": false,
"ask_skip_tags_on_launch": false,
"ask_job_type_on_launch": false,
"ask_limit_on_launch": false,
"ask_verbosity_on_launch": false,
"ask_inventory_on_launch": false,
"ask_credential_on_launch": false,
"survey_enabled": true,
"variables_needed_to_start": [
    "application_server_name",
    "server_location",
    "application_server_type",
    "ssh_keys"
],
"credential_needed_to_start": false,
"inventory_needed_to_start": false,
"job_template_data": {
    "name": "template name ",
    "id": 7,
    "description": ""
},
"defaults": {
    "extra_vars": {
        "application_server_name": "some name",
        "server_location": "some location",
        "application_server_type": "some type",
        "ssh_keys": [
            {
                "name": "key1"
            },
            {
                "name": "key2"
            },
            {
                "name": "key3"
            }
        ]
    },
    "diff_mode": false,
    "limit": "",
    "job_tags": "",
    "skip_tags": "",
    "job_type": "run",
    "verbosity": 2,
    "inventory": {
        "name": "AWX Tower (Localhost) my.awx.host",
        "id": 1
    },
    "credentials": [
        {
           ...
        }
    ],
    "scm_branch": ""
}}

Response

{
"variables_needed_to_start": [
    "'application_server_name' value missing",
    "'server_location' value missing",
    "'application_server_type' value missing",
    "'ssh_keys' value missing"
]}

I'm kinda confused, since I did everything according to the documentation. The values needed by the survey are even in the same Request Body. Could someone help with this problem?

I'm using AWX 16.0.0 Ansible Version 2.9.15 Thanks

xDevkas
  • 61
  • 2
  • 12
  • Why are you sending the `extra_vars` as a children of `defaults` ? Isn't it supposed to be a top level element in your request body ? – Zeitounator Mar 04 '21 at 20:55
  • @Zeitounator like stated in the docs I send a GET request to the ../launch endpoint, to get all the values needed by AWX. extra_vars is a children of defaults in this response. After that i add my variables to extra_vars and send it back as a POST. But I'll try your suggestion. – xDevkas Mar 05 '21 at 07:46
  • @Zeitounator the Request failes when I try to send the extra_vars as a top level element. – xDevkas Mar 08 '21 at 09:58
  • Did you find any solutions? I face the same issue :( – Marat Gainutdinov May 19 '21 at 10:24
  • @MaratGainutdinov actually yes! you have to send *JUST* the extra_vars as JSON. Not the whole response from the awx. But the "ask_variables_on_launch" flag has to be true. – xDevkas May 19 '21 at 14:03
  • yeah, did the same way and it worked. – Marat Gainutdinov May 19 '21 at 14:06

1 Answers1

0

So actually, you have to send just the extra vars, not the whole response + vars you get from the AWX. I don't know, if I didn't see this in the docs, or if it's just plain obvious and I did't get it.

ask_variables_on_launch still has to be true!

xDevkas
  • 61
  • 2
  • 12