redhat-cop / infra.aap_configuration

A collection of roles to manage Ansible Controller and previously Ansible Tower
https://galaxy.ansible.com/infra/controller_configuration
GNU General Public License v3.0
268 stars 141 forks source link

schedules: project and template named the same returns two results #877

Closed amunro-tsl closed 2 months ago

amunro-tsl commented 2 months ago

Summary

If the project and the template are named the same, schedule returns the following error:

"msg": "Request to /api/v2/unified_job_templates/?organization=2&name=helix_test returned 2 items, expected 1"

You should be able to name a project and template the same; this makes sense if you want to name the project/template/inventory the same to show they are linked, etc.

An improvement would be to allow you to specify if the resource is a project, template, etc. Another way to improve this is to prioritize template over other resource types.

Work around is to name the project helix_test Project. Obviously a quick change but it should not have this issue, and someone will need to try and figure out why its failing (time/effort), so a fix would be much appreciated.

Issue Type

Ansible, Collection, Controller details

infra.controller_configuration 2.9.0 (latest).

$ ansible --version
ansible [core 2.15.12]
  config file = /media/data/other-git/genomicsengland/gitlab/infra_services/config-mgt/ansible/aap/infrastructure-services-config/ansible.cfg
  configured module search path = ['/home/amunro/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/ansible
  ansible collection location = /home/amunro/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/linuxbrew/.linuxbrew/bin/ansible
  python version = 3.11.4 (main, Jun  6 2023, 22:16:46) [GCC 11.3.0] (/home/linuxbrew/.linuxbrew/opt/python@3.11/bin/python3.11)
  jinja version = 3.1.4
  libyaml = True

# /home/amunro/.ansible/collections/ansible_collections
Collection                     Version
------------------------------ -------
amazon.aws                     7.5.0  
ansible.controller             4.5.6  
infra.ah_configuration         2.0.6  
infra.controller_configuration 2.9.0  

# /home/linuxbrew/.linuxbrew/opt/python@3.11/lib/python3.11/site-packages/ansible_collections
Collection                     Version
------------------------------ -------
amazon.aws                     6.5.0  
ansible.netcommon              5.3.0  
ansible.posix                  1.5.4  
ansible.utils                  2.12.0 
ansible.windows                1.14.0 
arista.eos                     6.2.2  
awx.awx                        22.7.0 
azure.azcollection             1.19.0 
check_point.mgmt               5.1.1  
chocolatey.chocolatey          1.5.1  
cisco.aci                      2.8.0  
cisco.asa                      4.0.3  
cisco.dnac                     6.9.0  
cisco.intersight               1.0.27 
cisco.ios                      4.6.1  
cisco.iosxr                    5.0.3  
cisco.ise                      2.6.2  
cisco.meraki                   2.17.0 
cisco.mso                      2.5.0  
cisco.nso                      1.0.3  
cisco.nxos                     4.4.0  
cisco.ucs                      1.10.0 
cloud.common                   2.1.4  
cloudscale_ch.cloud            2.3.1  
community.aws                  6.4.0  
community.azure                2.0.0  
community.ciscosmb             1.0.7  
community.crypto               2.16.1 
community.digitalocean         1.24.0 
community.dns                  2.6.4  
community.docker               3.4.11 
community.fortios              1.0.0  
community.general              7.5.2  
community.google               1.0.0  
community.grafana              1.6.1  
community.hashi_vault          5.0.1  
community.hrobot               1.8.2  
community.libvirt              1.3.0  
community.mongodb              1.6.3  
community.mysql                3.8.0  
community.network              5.0.2  
community.okd                  2.3.0  
community.postgresql           2.4.3  
community.proxysql             1.5.1  
community.rabbitmq             1.2.3  
community.routeros             2.11.0 
community.sap                  1.0.0  
community.sap_libs             1.4.1  
community.skydive              1.0.0  
community.sops                 1.6.7  
community.vmware               3.11.1 
community.windows              1.13.0 
community.zabbix               2.2.0  
containers.podman              1.11.0 
cyberark.conjur                1.2.2  
cyberark.pas                   1.0.23 
dellemc.enterprise_sonic       2.2.0  
dellemc.openmanage             7.6.1  
dellemc.powerflex              1.9.0  
dellemc.unity                  1.7.1  
f5networks.f5_modules          1.27.1 
fortinet.fortimanager          2.3.0  
fortinet.fortios               2.3.4  
frr.frr                        2.0.2  
gluster.gluster                1.0.2  
google.cloud                   1.3.0  
grafana.grafana                2.2.3  
hetzner.hcloud                 1.16.0 
hpe.nimble                     1.1.4  
ibm.qradar                     2.1.0  
ibm.spectrum_virtualize        1.12.0 
ibm.storage_virtualize         2.1.0  
infinidat.infinibox            1.3.12 
infoblox.nios_modules          1.5.0  
inspur.ispim                   1.3.0  
inspur.sm                      2.3.0  
junipernetworks.junos          5.3.1  
kubernetes.core                2.4.0  
lowlydba.sqlserver             2.2.2  
microsoft.ad                   1.4.1  
netapp.aws                     21.7.1 
netapp.azure                   21.10.1
netapp.cloudmanager            21.22.1
netapp.elementsw               21.7.0 
netapp.ontap                   22.8.3 
netapp.storagegrid             21.11.1
netapp.um_info                 21.8.1 
netapp_eseries.santricity      1.4.0  
netbox.netbox                  3.15.0 
ngine_io.cloudstack            2.3.0  
ngine_io.exoscale              1.1.0  
ngine_io.vultr                 1.1.3  
openstack.cloud                2.2.0  
openvswitch.openvswitch        2.1.1  
ovirt.ovirt                    3.2.0  
purestorage.flasharray         1.24.0 
purestorage.flashblade         1.14.0 
purestorage.fusion             1.6.0  
sensu.sensu_go                 1.14.0 
servicenow.servicenow          1.0.6  
splunk.es                      2.1.2  
t_systems_mms.icinga_director  1.33.1 
telekom_mms.icinga_director    1.35.0 
theforeman.foreman             3.15.0 
vmware.vmware_rest             2.3.1  
vultr.cloud                    1.11.0 
vyos.vyos                      4.1.0  
wti.remote                     1.0.5  

Controller version: 4.5.7

OS / ENVIRONMENT

Linux (ubuntu 22.04).

Desired Behavior

Prioritize the template?

Actual Behavior

Fails.

Please give some details of what is actually happening. Include a [minimum complete verifiable example] with:

STEPS TO REPRODUCE

---
controller_projects:
  - name: helix_test
    organization: Infrastructure_Services
    scm_branch: INS-000/helix-test
    scm_type: git
    scm_update_on_launch: true
    scm_url: https://gitlab.com/genomicsengland/infra_services/config_mgt/ansible/cluster-double-helix.git
    credential: "GEL Gitlab - ansible read"
    notification_templates_error: Slack ansible_alerts

---
controller_templates:
- name: helix_test
  job_type: run
  organization: Infrastructure_Services
  inventory: helix_test
  project: helix_test
  execution_environment: Automation Hub Default execution environment
  playbook: site.yml
  credentials:
  - helix_test
  instance_groups:
  - ansible_dev
  verbosity: 0
  become_enabled: true
  notification_templates_error: Slack ansible_alerts
  ask_variables_on_launch: false
  ask_verbosity_on_launch: false

---
controller_schedules:
  - name: helix_test
    organization: Infrastructure_Services
    description: Run helix_test template on a schedule so we are alerted when AAP has issue running jobs
    unified_job_template: helix_test
    rrule: "DTSTART:20240721T000000Z RRULE:FREQ=HOURLY;INTERVAL=4"
    extra_data:
      scheduled: true
    verbosity: 1
Tompage1994 commented 2 months ago

Hi @amunro-tsl, unfortunately this isn't directly applicable for this collection, instead you'll need to raise the same thing over at the awx.awx collection. I've an idea on how it might be done so if you do raise it over there and I get time I may raise a PR for it.

My thoughts are that you would have an optional unified_job_template_type option which gets added as a query param on the search for the UJT.

If and when it's accepted there, we can add the relevant change here if required.