Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jon4hz opened this issue Aug 29, 2023 · 2 comments
Closed
Labels
bug Something isn't working new New issue, this should be removed once reviewed

Comments

@jon4hz
Copy link
Contributor

jon4hz commented Aug 29, 2023

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

  • Bug Report

Ansible, Collection, Controller details

ansible-core: 2.15.3
controller_configuration: 2.5.0
Controller version: 4.4.0
  • ansible installation method: pip

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"
@jon4hz jon4hz added bug Something isn't working new New issue, this should be removed once reviewed labels Aug 29, 2023
@Tompage1994
Copy link
Collaborator

Closed by #686

@jon4hz
Copy link
Contributor Author

jon4hz commented Aug 30, 2023

wow that was fast. Thanks a lot :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working new New issue, this should be removed once reviewed
Projects
None yet
Development

No branches or pull requests

2 participants