---
- name: Get RHEL username using psonoci
  ansible.builtin.command:
    cmd: 'psonoci secret get {{ rhel_sub_psono_secret_id }} username'
  when: rhel_sub_psono_secret_id
  no_log: True
  register: reg_rhel_sub_register_username
  retries: 3
  delay: 10
  until: reg_rhel_sub_register_username is successful

- name: Get RHEL password using psonoci
  ansible.builtin.command:
    cmd: 'psonoci secret get {{ rhel_sub_psono_secret_id }} password'
  when: rhel_sub_psono_secret_id
  no_log: True
  register: reg_rhel_sub_register_password
  retries: 3
  delay: 10
  until: reg_rhel_sub_register_password is successful
  
- name: Register RHEL subscription
  community.general.redhat_subscription:
    state: present
    username: '{{ reg_rhel_sub_register_username.stdout | d(rhel_subscription_user) }}'
    password: '{{ reg_rhel_sub_register_password.stdout | d(rhel_subscription_password) }}'
    auto_attach: true
  register: reg_rhel_sub_register_el
  retries: 3
  delay: 10
  until: reg_rhel_sub_register_el is successful
