redhat-cop / infra.aap_configuration

A collection of roles to manage Ansible Automation Platform 2.5+ with code
https://galaxy.ansible.com/infra/aap_configuration
GNU General Public License v3.0
275 stars 141 forks source link

dispatch role failes to create organization if instance group doesn't exist yet #685

Closed jon4hz closed 1 year ago

jon4hz commented 1 year ago

Summary

The dispatch role failes to create an organization if you assign an instance group to this organization that doesn't exist yet. I experienced this issue when I tried to create an org and an instance group in the same run.

Issue Type

Ansible, Collection, Controller details

ansible-core: 2.15.3
controller_configuration: 2.5.0
Controller version: 4.4.0

OS / ENVIRONMENT

The playbook was executed in a gitlab pipeline. The runner image is based on alpine 3.18.

Desired Behavior

I'd expect the dispatch role to create the instance group before creating the organization. Or create the organization without the instance group first and then assign it after creating the instance group (same as the role does for ee).

Actual Behavior

The role fails because the instance group doesn't exist yet and therefore can't be assigned to the org.

TASK [infra.controller_configuration.organizations : Configure Controller Organizations | Wait for finish the organization creation] ***
failed: [my.host] (item={'failed': 0, 'started': 1, 'finished': 0, 'ansible_job_id': 'j600586684650.1889', 'results_file': '/app/.ansible_async/j600586684650.1889', 'changed': False, '__controller_organizations_item': {'name': 'myorg', 'description': 'myorg', 'instance_groups': 'myorg default'}, 'ansible_loop_var': '__controller_organizations_item'}) => {"__organizations_job_async_results_item": {"__controller_organizations_item": {"description": "myorg", "instance_groups": "myorg default", "name": "myorg"}, "ansible_job_id": "j600586684650.1889", "ansible_loop_var": "__controller_organizations_item", "changed": false, "failed": 0, "finished": 0, "results_file": "/app/.ansible_async/j600586684650.1889", "started": 1}, "ansible_job_id": "j600586684650.1889", "ansible_loop_var": "__organizations_job_async_results_item", "attempts": 1, "changed": false, "finished": 1, "msg": "Request to /api/v2/instance_groups/?name=myorg+default returned 0 items, expected 1", "query": {"name": "myorg default"}, "response": {"json": {"count": 0, "next": null, "previous": null, "results": []}, "status_code": 200}, "results_file": "/app/.ansible_async/j600586684650.1889", "started": 1, "stderr": "", "stderr_lines": [], "stdout": "", "stdout_lines": [], "total_results": 0}

STEPS TO REPRODUCE

---
- name: Read and deploy filetree of {{ orgs }}
  hosts: automationcontroller
  connection: local
  gather_facts: false
  vars:
    controller_configuration_projects_async_retries: 120
    controller_configuration_projects_async_delay: 2
    controller_username: "{{ vault_controller_username }}"
    controller_password: "{{ vault_controller_password }}"
    controller_hostname: "{{ vault_controller_hostname }}"
    controller_validate_certs: true

  pre_tasks:
    - name: "Setup authentication (block)"
      no_log: "{{ controller_configuration_filetree_read_secure_logging | ansible.builtin.bool }}"
      when: controller_oauthtoken is not defined
      tags:
        - always
      block:
        - name: "Get the Authentication Token for the future requests"
          ansible.builtin.uri:
            url: "https://{{ controller_hostname }}/api/v2/tokens/"
            user: "{{ controller_username }}"
            password: "{{ controller_password }}"
            method: POST
            force_basic_auth: true
            validate_certs: "{{ controller_validate_certs }}"
            status_code: 201
          check_mode: false
          changed_when: false
          register: authtoken_res

        - name: "Set the oauth token to be used since now"
          ansible.builtin.set_fact:
            controller_oauthtoken: "{{ authtoken_res.json.token }}"
            controller_oauthtoken_url: "{{ authtoken_res.json.url }}"

  roles:
    - infra.controller_configuration.filetree_read
    - infra.controller_configuration.dispatch

  post_tasks:
    - name: "Delete the Authentication Token used"
      ansible.builtin.uri:
        url: "https://{{ controller_hostname }}{{ controller_oauthtoken_url }}"
        user: "{{ controller_username }}"
        password: "{{ controller_password }}"
        method: DELETE
        force_basic_auth: true
        validate_certs: "{{ controller_validate_certs }}"
        status_code: 204
      when: controller_oauthtoken_url is defined
controller_organizations:
  - name: "{{ orgs }}"
    instance_groups: "{{ orgs }} new_instance_group"

controller_instance_groups:
  - name: "{{ orgs }} new_instance_group"
    policy_instance_minimum: "0"
    policy_instance_percentage: "100"
    instances:
      - "my.ansible.host"
Tompage1994 commented 1 year ago

Closed by #686

jon4hz commented 1 year ago

wow that was fast. Thanks a lot :D