Search code examples
ansibleansible-toweransible-awx

ansible awx/tower not accepting list of values in a variable


I am trying to launch an awx/tower job template passing a list of values in a variable but the task is getting executed only on one target host.

sample request

curl -H "Content-Type: application/json" -X POST -s -u admin:admin123 -d '{ "extra_vars": { "domain": "dom-cn-1", "targets": "dev-cn-c1", "targets": "dev-cn-c2", "fwcmd": "fw sam -v -J src 192.168.10.10" }}' -k https://172.16.102.4/api/v2/job_templates/10/launch/

The above command does not execute as expected and runs on a single host. However, this is working as expected when I run the same playbook via cli.

vars file snip

domain: dom-cn-1
targets:
    - dev-cn-c1
    - dev-cn-c2

Playbook file

- name: "Create output file"
  check_point_mgmt:
    command: run-script
    parameters:
      script-name: "Create output file"
      script: "fw sam -v  -J src  192.168.10.10"
      targets: "{{ targets }}"
    session-data: "{{login_response}}"

Solution

  • Let's extract your json in your curl command:

    {
      "extra_vars": { 
        "domain": "dom-cn-1",
        "targets": "dev-cn-c1",
        "targets": "dev-cn-c2",
        "fwcmd": "fw sam -v -J src 192.168.10.10"
      }
    }
    

    You are not passing a list but twice the same parameter with different values. You have to correct you json like this:

    {
      "extra_vars": { 
        "domain": "dom-cn-1",
        "targets": ["dev-cn-c1", "dev-cn-c2"],
        "fwcmd": "fw sam -v -J src 192.168.10.10"
      }
    }