ansibleguy76/ansibleforms

Add __instance_groups__ to allow to launch a job template with a instance_groups parameter

Closed this issue · 15 comments

Is your feature request related to a problem? Please describe.
https://docs.ansible.com/ansible/latest/collections/awx/awx/job_launch_module.html#parameter-instance_groups

In recent awx deployments you can select the instance group at joblaunch (if promp instance groups is active). It would be nice if extra var __instance_groups__ can be translated to an instance group list

Describe alternatives you've considered
An awx template per instance group (like the old versions of AWX where this is not possible)

will be added to 5.0.0 (still beta). Expect a build in 15 minutes.
Let me know if it all works.

it will be instanceGroups as field or instanceGroups (on form level)

I have no recent AWX to test it

form:

- name: igtest
  type: awx
  template: Gather_Facts_Custom
  description: ""
  roles:
    - admin
  categories:
    - Default
  tileClass: has-background-info-light
  icon: fa-brands fa-linux
  fields:
    - name: __instanceGroups__ 
      type: enum
      multiple: true
      values:
        - "IGA"
        - "IGB"
instance_groups:
  - Incorrect type. Expected pk value, received str.
failed to launch awx template Gather_Facts_Custom 2024-01-18 20:37:07
failed to launch Gather_Facts_Custom
instance_groups:
  - Incorrect type. Expected pk value, received str.

Is the code in the devop branch then I can take a look :)

(when looking at a job that has been launched in awx with the ask instance group --> this is added)

        "instance_group": {
            "id": 7,
            "name": "IGB",
            "is_container_group": false
        },

I'll do some postman tests tomorrow

this piece op python can launch a template with a given instance group. but it needs to be an id.

launch_data = {
            "instance_groups": [7]
            }
    r = requests.post(
        controller_host + endpoint,
        headers=headers,
        auth=HTTPBasicAuth(controller_user,controller_password),
        data=json.dumps(launch_data),
    )

But I can work around this by using this
https://ansibleforms.com/faq/#query-information-from-awx-or-tower

editing my form for testing

values:
        - "id of IGA"
        - "id of IGB"

launches with succes!

in the docs. instance groups is an array of strings.
what you show is an object

I will probably have to lookup the id first, just like with environments. I'll make the change.

new beta being built

does it need te be a list of names or a single string?

["IGA"]

returns
could not find instance group IGA

If i put it as just a string (remove multiple : true)
it returns:

could not find instance group A

-> i'll debug a bit in the container tonight

update:

When I give a list (after I gave the user som more rights :)


instance_groups:
  - Incorrect type. Expected pk value, received OrderedDict.

I expect an array of strings... I could potentially allow a single value and force it to a list.
Unless AWX doesn't allow a list.

in my python example

launch_data = {
"instance_groups": [7,8]
}

works

"instance_groups": ["7","8"]

also works

found the issue... my bad, was fetching instancegroups, but forgot to return the "id" only

building new beta now, instanceGroups can now be either string or array of strings. It can be defined in the form-root as "instanceGroups" or as a field "__instanceGroups__"

it works!