ansibleguy76 / ansibleforms

A webapplication to create pretty advanced forms to run ansible playbooks or awx templates.
https://ansibleforms.com/
GNU General Public License v3.0
66 stars 10 forks source link

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

Closed MalfuncEddie closed 7 months ago

MalfuncEddie commented 8 months ago

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)

ansibleguy76 commented 8 months ago

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

ansibleguy76 commented 8 months ago

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

ansibleguy76 commented 8 months ago

I have no recent AWX to test it

MalfuncEddie commented 8 months ago

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

MalfuncEddie commented 8 months ago

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!

ansibleguy76 commented 8 months ago

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

ansibleguy76 commented 7 months ago

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

ansibleguy76 commented 7 months ago

new beta being built

MalfuncEddie commented 7 months ago

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.
ansibleguy76 commented 7 months ago

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.

MalfuncEddie commented 7 months ago

in my python example

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

works

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

also works

ansibleguy76 commented 7 months ago

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

ansibleguy76 commented 7 months ago

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__"

MalfuncEddie commented 7 months ago

it works!

ansibleguy76 commented 7 months ago

cool