# Copyright (c) 2019 Dell Inc. or its subsidiaries. All Rights Reserved.
---
- name: Gather AWX details
  set_fact:
    awx_details: '{ "{{ tower_user_info.username }}": {"username": "{{ tower_user_info.username }}", "password": "{{ user_password }}"} }'
  no_log: "{{ enforce_no_log }}"

- name: Update existing creds with new credentials
  set_fact:
    awx_details: "{{ vault_awx_creds.data | combine(awx_details) }}"
  no_log: "{{ enforce_no_log }}"

- name: Store AWX details
  shell: >
    kubectl exec -it -n ngci-consul "{{ consul_pod_name.stdout }}" -c ngci-secret-storage-consul -- 
    curl -X POST -H X-Vault-Token:{{ ldap_login_token.stdout }} -H 'Content-Type: application/json' {{ ngci_vault_internal_service_address }}/v1/{{ awx_details_path }} -d '{{ awx_details | to_json }}'
  no_log: "{{ enforce_no_log }}"
  register: vault_add_awx_creds
  until: vault_add_awx_creds.rc == 0
  delay: 30
  retries: 30