main.yml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ---
  2. - fail:
  3. msg: "This role is only supported for Red Hat hosts"
  4. when: ansible_distribution != 'RedHat'
  5. - name: Install Red Hat Subscription manager
  6. yum:
  7. name: subscription-manager
  8. state: present
  9. register: result
  10. until: result is succeeded
  11. - name: Is host already registered?
  12. command: "subscription-manager version"
  13. register: rh_subscribed
  14. changed_when: False
  15. - name: Register host using user/password
  16. redhat_subscription:
  17. username: "{{ rhsub_user }}"
  18. password: "{{ rhsub_pass }}"
  19. register: rh_subscription
  20. until: rh_subscription is succeeded
  21. when:
  22. - "'not registered' in rh_subscribed.stdout"
  23. - rhsub_user is defined
  24. - rhsub_pass is defined
  25. - name: Register host using activation key
  26. redhat_subscription:
  27. activationkey: "{{ rhsub_ak }}"
  28. org_id: "{{ rhsub_orgid }}"
  29. register: rh_subscription
  30. until: rh_subscription is succeeded
  31. when:
  32. - "'not registered' in rh_subscribed.stdout"
  33. - rhsub_ak is defined
  34. - rhsub_orgid is defined
  35. - name: Determine if OpenShift Pool Already Attached
  36. command: "subscription-manager list --consumed --pool-only --matches '*OpenShift*'"
  37. register: openshift_pool_attached
  38. changed_when: False
  39. ignore_errors: yes
  40. - name: Attach to OpenShift Pool
  41. command: "subscription-manager attach --pool {{ rhsub_pool }}"
  42. register: openshift_pool_attached
  43. changed_when: "'Successfully attached a subscription' in openshift_pool_attached.stdout"
  44. when: rhsub_pool not in openshift_pool_attached.stdout
  45. - import_tasks: satellite.yml
  46. when:
  47. - rhsub_server is defined
  48. - rhsub_server