You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.0 KiB

  1. ---
  2. - name: Gather host facts to get ansible_distribution_version ansible_distribution_major_version
  3. setup:
  4. gather_subset: '!all'
  5. filter: ansible_distribution_*version
  6. - name: Add proxy to yum.conf or dnf.conf if http_proxy is defined
  7. ini_file:
  8. path: "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('/etc/yum.conf','/etc/dnf/dnf.conf') }}"
  9. section: main
  10. option: proxy
  11. value: "{{ http_proxy | default(omit) }}"
  12. state: "{{ http_proxy | default(False) | ternary('present', 'absent') }}"
  13. no_extra_spaces: true
  14. mode: 0644
  15. become: true
  16. when: not skip_http_proxy_on_os_packages
  17. - name: Add proxy to RHEL subscription-manager if http_proxy is defined
  18. command: /sbin/subscription-manager config --server.proxy_hostname={{ http_proxy | regex_replace(':\d+$') }} --server.proxy_port={{ http_proxy | regex_replace('^.*:') }}
  19. become: true
  20. when:
  21. - not skip_http_proxy_on_os_packages
  22. - http_proxy is defined
  23. - name: Check RHEL subscription-manager status
  24. command: /sbin/subscription-manager status
  25. register: rh_subscription_status
  26. changed_when: "rh_subscription_status != 0"
  27. ignore_errors: true # noqa ignore-errors
  28. become: true
  29. - name: RHEL subscription Organization ID/Activation Key registration
  30. redhat_subscription:
  31. state: present
  32. org_id: "{{ rh_subscription_org_id }}"
  33. activationkey: "{{ rh_subscription_activation_key }}"
  34. auto_attach: true
  35. force_register: true
  36. syspurpose:
  37. usage: "{{ rh_subscription_usage }}"
  38. role: "{{ rh_subscription_role }}"
  39. service_level_agreement: "{{ rh_subscription_sla }}"
  40. sync: true
  41. notify: RHEL auto-attach subscription
  42. ignore_errors: true # noqa ignore-errors
  43. become: true
  44. when:
  45. - rh_subscription_org_id is defined
  46. - rh_subscription_status.changed
  47. # this task has no_log set to prevent logging security sensitive information such as subscription passwords
  48. - name: RHEL subscription Username/Password registration
  49. redhat_subscription:
  50. state: present
  51. username: "{{ rh_subscription_username }}"
  52. password: "{{ rh_subscription_password }}"
  53. auto_attach: true
  54. force_register: true
  55. syspurpose:
  56. usage: "{{ rh_subscription_usage }}"
  57. role: "{{ rh_subscription_role }}"
  58. service_level_agreement: "{{ rh_subscription_sla }}"
  59. sync: true
  60. notify: RHEL auto-attach subscription
  61. ignore_errors: true # noqa ignore-errors
  62. become: true
  63. no_log: "{{ not (unsafe_show_logs|bool) }}"
  64. when:
  65. - rh_subscription_username is defined
  66. - rh_subscription_status.changed
  67. # container-selinux is in extras repo
  68. - name: Enable RHEL 7 repos
  69. rhsm_repository:
  70. name:
  71. - "rhel-7-server-rpms"
  72. - "rhel-7-server-extras-rpms"
  73. state: "{{ 'enabled' if (rhel_enable_repos | default(True) | bool) else 'disabled' }}"
  74. when:
  75. - ansible_distribution_major_version == "7"
  76. # container-selinux is in appstream repo
  77. - name: Enable RHEL 8 repos
  78. rhsm_repository:
  79. name:
  80. - "rhel-8-for-*-baseos-rpms"
  81. - "rhel-8-for-*-appstream-rpms"
  82. state: "{{ 'enabled' if (rhel_enable_repos | default(True) | bool) else 'disabled' }}"
  83. when:
  84. - ansible_distribution_major_version == "8"
  85. - name: Check presence of fastestmirror.conf
  86. stat:
  87. path: /etc/yum/pluginconf.d/fastestmirror.conf
  88. get_attributes: no
  89. get_checksum: no
  90. get_mime: no
  91. register: fastestmirror
  92. # the fastestmirror plugin can actually slow down Ansible deployments
  93. - name: Disable fastestmirror plugin if requested
  94. lineinfile:
  95. dest: /etc/yum/pluginconf.d/fastestmirror.conf
  96. regexp: "^enabled=.*"
  97. line: "enabled=0"
  98. state: present
  99. become: true
  100. when:
  101. - fastestmirror.stat.exists
  102. - not centos_fastestmirror_enabled
  103. # libselinux-python is required on SELinux enabled hosts
  104. # See https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#managed-node-requirements
  105. - name: Install libselinux python package
  106. package:
  107. name: "{{ ( (ansible_distribution_major_version | int) < 8) | ternary('libselinux-python','python3-libselinux') }}"
  108. state: present
  109. become: true