diff --git a/playbooks/aap_get_admin_credentials.yml b/playbooks/aap_get_admin_credentials.yml index a6792e4..9e39760 100644 --- a/playbooks/aap_get_admin_credentials.yml +++ b/playbooks/aap_get_admin_credentials.yml @@ -6,47 +6,14 @@ gather_facts: false vars: kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" + # Public overrides — keep aap_* names so existing callers do not regress aap_namespace: ansible-automation-platform aap_route_name: aap aap_secret_name: aap-admin-password + admin_cred_label: AAP + admin_cred_namespace: "{{ aap_namespace }}" + admin_cred_route_name: "{{ aap_route_name }}" + admin_cred_secret_name: "{{ aap_secret_name }}" tasks: - - name: Retrieve API hostname for AAP - kubernetes.core.k8s_info: - api_version: route.openshift.io/v1 - kind: Route - namespace: "{{ aap_namespace }}" - name: "{{ aap_route_name }}" - register: aap_host - until: aap_host.resources | length == 1 - retries: 20 - delay: 5 - - - name: Set ansible_host - ansible.builtin.set_fact: - ansible_host: "{{ aap_host.resources[0].spec.host }}" - - - name: Retrieve admin password for AAP - kubernetes.core.k8s_info: - kind: Secret - namespace: "{{ aap_namespace }}" - name: "{{ aap_secret_name }}" - register: admin_pw - until: admin_pw.resources | length == 1 - retries: 20 - delay: 5 - - - name: Set admin_password fact - ansible.builtin.set_fact: - admin_password: "{{ admin_pw.resources[0].data.password | b64decode }}" - - - name: Report AAP Endpoint - ansible.builtin.debug: - msg: "AAP Endpoint: https://{{ ansible_host }}" - - - name: Report AAP User - ansible.builtin.debug: - msg: "AAP Admin User: admin" - - - name: Report AAP Admin Password - ansible.builtin.debug: - msg: "AAP Admin Password: {{ admin_password }}" + - name: Retrieve and display AAP admin credentials + ansible.builtin.include_tasks: tasks/aap_ao_get_admin_credentials.yml diff --git a/playbooks/ao_get_admin_credentials.yml b/playbooks/ao_get_admin_credentials.yml new file mode 100644 index 0000000..e904885 --- /dev/null +++ b/playbooks/ao_get_admin_credentials.yml @@ -0,0 +1,19 @@ +--- +- name: Retrieve Credentials for AO on OpenShift + become: false + connection: local + hosts: localhost + gather_facts: false + vars: + kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" + # Public overrides — keep ao_* names so existing callers do not regress + ao_namespace: automation-orchestrator + ao_route_name: orchestrator + ao_secret_name: orchestrator-initial-admin-password + admin_cred_label: AO + admin_cred_namespace: "{{ ao_namespace }}" + admin_cred_route_name: "{{ ao_route_name }}" + admin_cred_secret_name: "{{ ao_secret_name }}" + tasks: + - name: Retrieve and display AO admin credentials + ansible.builtin.include_tasks: tasks/aap_ao_get_admin_credentials.yml diff --git a/playbooks/tasks/aap_ao_get_admin_credentials.yml b/playbooks/tasks/aap_ao_get_admin_credentials.yml new file mode 100644 index 0000000..b37ebce --- /dev/null +++ b/playbooks/tasks/aap_ao_get_admin_credentials.yml @@ -0,0 +1,52 @@ +--- +# Shared workflow to retrieve an OpenShift route hostname and admin password secret, +# then display endpoint/user/password. +# +# Expected variables: +# admin_cred_label: Product label used in debug messages (e.g. AAP, AO) +# admin_cred_namespace: Namespace containing the Route and Secret +# admin_cred_route_name: Name of the Route resource +# admin_cred_secret_name: Name of the Secret containing the admin password +# Optional: +# admin_cred_user: Admin username to report (default: admin) +# admin_cred_secret_key: Secret data key for the password (default: password) +- name: Retrieve API hostname for {{ admin_cred_label }} + kubernetes.core.k8s_info: + api_version: route.openshift.io/v1 + kind: Route + namespace: "{{ admin_cred_namespace }}" + name: "{{ admin_cred_route_name }}" + register: admin_cred_route + until: admin_cred_route.resources | length == 1 + retries: 20 + delay: 5 + +- name: Set ansible_host + ansible.builtin.set_fact: + ansible_host: "{{ admin_cred_route.resources[0].spec.host }}" + +- name: Retrieve admin password for {{ admin_cred_label }} + kubernetes.core.k8s_info: + kind: Secret + namespace: "{{ admin_cred_namespace }}" + name: "{{ admin_cred_secret_name }}" + register: admin_pw + until: admin_pw.resources | length == 1 + retries: 20 + delay: 5 + +- name: Set admin_password fact + ansible.builtin.set_fact: + admin_password: "{{ admin_pw.resources[0].data[admin_cred_secret_key | default('password')] | b64decode }}" + +- name: Report {{ admin_cred_label }} Endpoint + ansible.builtin.debug: + msg: "{{ admin_cred_label }} Endpoint: https://{{ ansible_host }}" + +- name: Report {{ admin_cred_label }} User + ansible.builtin.debug: + msg: "{{ admin_cred_label }} Admin User: {{ admin_cred_user | default('admin') }}" + +- name: Report {{ admin_cred_label }} Admin Password + ansible.builtin.debug: + msg: "{{ admin_cred_label }} Admin Password: {{ admin_password }}"