main.yml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ---
  2. - name: "Initialize rhsm_password variable if vars_prompt was used"
  3. set_fact:
  4. rhsm_password: "{{ hostvars.localhost.rhsm_password }}"
  5. when:
  6. - rhsm_password is not defined or rhsm_password is none or rhsm_password|trim == ''
  7. - name: "Initializing Subscription Manager authentication method"
  8. set_fact:
  9. rhsm_authentication: false
  10. # 'rhsm_activationkey' will take precedence even if 'rhsm_username' and 'rhsm_password' are also set
  11. - name: "Setting Subscription Manager Activation Key Fact"
  12. set_fact:
  13. rhsm_authentication: "key"
  14. when:
  15. - rhsm_activationkey is defined
  16. - rhsm_activationkey is not none
  17. - rhsm_activationkey|trim != ''
  18. - not rhsm_authentication
  19. # If 'rhsm_username' and 'rhsm_password' are set but not 'rhsm_activationkey', set 'rhsm_authentication' to password
  20. - name: "Setting Subscription Manager Username and Password Fact"
  21. set_fact:
  22. rhsm_authentication: "password"
  23. when:
  24. - rhsm_username is defined
  25. - rhsm_username is not none
  26. - rhsm_username|trim != ''
  27. - rhsm_password is defined
  28. - rhsm_password is not none
  29. - rhsm_password|trim != ''
  30. - not rhsm_authentication
  31. - name: "Initializing registration status"
  32. set_fact:
  33. registered: false
  34. - name: "Checking subscription status (a failure means it is not registered and will be)"
  35. command: "/usr/bin/subscription-manager status"
  36. ignore_errors: yes
  37. changed_when: no
  38. register: check_if_registered
  39. - name: "Set registration fact if system is already registered"
  40. set_fact:
  41. registered: true
  42. when: check_if_registered.rc == 0
  43. - name: "Cleaning any old subscriptions"
  44. command: "/usr/bin/subscription-manager clean"
  45. when:
  46. - not registered
  47. - rhsm_authentication is defined
  48. - name: "Install Satellite certificate"
  49. command: "rpm -Uvh --force http://{{ rhsm_satellite }}/pub/katello-ca-consumer-latest.noarch.rpm"
  50. when:
  51. - not registered
  52. - rhsm_satellite is defined
  53. - rhsm_satellite is not none
  54. - rhsm_satellite|trim != ''
  55. - name: "Register to Satellite using activation key"
  56. command: "/usr/bin/subscription-manager register --activationkey={{ rhsm_activationkey }} --org='{{ rhsm_org }}'"
  57. when:
  58. - not registered
  59. - rhsm_authentication == 'key'
  60. - rhsm_satellite is defined
  61. - rhsm_satellite is not none
  62. - rhsm_satellite|trim != ''
  63. # This can apply to either Hosted or Satellite
  64. - name: "Register using username and password"
  65. command: "/usr/bin/subscription-manager register --username={{ rhsm_username }} --password={{ rhsm_password }}"
  66. no_log: true
  67. when:
  68. - not registered
  69. - rhsm_authentication == "password"
  70. - rhsm_org is not defined or rhsm_org is none or rhsm_org|trim == ''
  71. # This can apply to either Hosted or Satellite
  72. - name: "Register using username, password and organization"
  73. command: "/usr/bin/subscription-manager register --username={{ rhsm_username }} --password={{ rhsm_password }} --org={{ rhsm_org }}"
  74. no_log: true
  75. when:
  76. - not registered
  77. - rhsm_authentication == "password"
  78. - rhsm_org is defined
  79. - rhsm_org is not none
  80. - rhsm_org|trim != ''
  81. - name: "Auto-attach to Subscription Manager Pool"
  82. command: "/usr/bin/subscription-manager attach --auto"
  83. when:
  84. - not registered
  85. - rhsm_pool is undefined or rhsm_pool is none or rhsm_pool|trim == ''
  86. - name: "Attach to a specific pool"
  87. command: "/usr/bin/subscription-manager attach --pool={{ rhsm_pool }}"
  88. when:
  89. - rhsm_pool is defined
  90. - rhsm_pool is not none
  91. - rhsm_pool|trim != ''
  92. - not registered
  93. - name: "Disable all repositories"
  94. command: "/usr/bin/subscription-manager repos --disable=*"
  95. when:
  96. - not registered
  97. - rhsm_repos is defined
  98. - rhsm_repos is not none
  99. - rhsm_repos|trim != ''
  100. - name: "Enable specified repositories"
  101. command: "/usr/bin/subscription-manager repos --enable={{ item }}"
  102. with_items: "{{ rhsm_repos }}"
  103. when:
  104. - not registered
  105. - rhsm_repos is defined
  106. - rhsm_repos is not none
  107. - rhsm_repos|trim != ''