---
- name: "Set awx_base_url"
  set_fact:
    awx_base_url: "https://{{ stage }}-kube-awx.{{ domain }}"
  tags:
    - awx

- name: "Checkin if awx in k8s cluster is avail"
  delegate_to: localhost
  uri:
    url: "{{ awx_base_url }}/api/login"
    method: GET
    user: "{{ awx_admin_username }}"
    password: "{{ awx_admin_password }}"
    return_content: true
    validate_certs: false
    force_basic_auth: yes
    status_code: 200
  register: check_awx_available
  retries: 15
  delay: 10
  until: check_awx_available.status in [200]
  when:
  - inventory_hostname == groups['kube_control_plane'][0]
  tags:
    - awx

- name: "Authenticating with awx server"
  delegate_to: localhost
  uri:
    url: "{{ awx_base_url }}/api/login"
    method: GET
    user: "{{ awx_admin_username }}"
    password: "{{ awx_admin_password }}"
    return_content: true
    validate_certs: false
    force_basic_auth: yes
    status_code: 200
  register: authentication_response
  tags:
    - awx

- name: DEBUG
  debug:
    msg: "{{ authentication_response }}"
  tags:
    - awx
  when:
    - debug

- name: "Configure some stuff"
  include_tasks: awx-config.yml
  vars:
    awx_base_url: "https://{{ stage }}-kube-awx.{{ domain }}"
    awx_rest_api_access_user: "{{ awx_admin_username }}"
    awx_rest_api_access_pw: "{{ awx_admin_password }}"
  when:
  - inventory_hostname == groups['kube_control_plane'][0]
  args:
    apply:
      tags:
        - awx
  tags:
    - awx
