2020-11-25 00:33:00 +08:00
|
|
|
---
|
|
|
|
- name: Gather host facts to get ansible_distribution_version ansible_distribution_major_version
|
|
|
|
setup:
|
|
|
|
gather_subset: '!all'
|
|
|
|
filter: ansible_distribution_*version
|
|
|
|
|
2021-01-08 02:50:53 +08:00
|
|
|
- name: Add proxy to yum.conf or dnf.conf if http_proxy is defined
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.ini_file:
|
2023-07-05 11:36:54 +08:00
|
|
|
path: "{{ ((ansible_distribution_major_version | int) < 8) | ternary('/etc/yum.conf', '/etc/dnf/dnf.conf') }}"
|
2021-01-08 02:50:53 +08:00
|
|
|
section: main
|
|
|
|
option: proxy
|
|
|
|
value: "{{ http_proxy | default(omit) }}"
|
|
|
|
state: "{{ http_proxy | default(False) | ternary('present', 'absent') }}"
|
|
|
|
no_extra_spaces: true
|
2024-07-26 09:42:20 +08:00
|
|
|
mode: "0644"
|
2021-01-08 02:50:53 +08:00
|
|
|
become: true
|
|
|
|
when: not skip_http_proxy_on_os_packages
|
|
|
|
|
2021-09-27 23:47:35 +08:00
|
|
|
- name: Add proxy to RHEL subscription-manager if http_proxy is defined
|
2023-06-19 17:24:21 +08:00
|
|
|
command: /sbin/subscription-manager config --server.proxy_hostname={{ http_proxy | regex_replace(':\d+$') | regex_replace('^.*://') }} --server.proxy_port={{ http_proxy | regex_replace('^.*:') }}
|
2021-09-27 23:47:35 +08:00
|
|
|
become: true
|
|
|
|
when:
|
|
|
|
- not skip_http_proxy_on_os_packages
|
|
|
|
- http_proxy is defined
|
|
|
|
|
2020-11-25 00:33:00 +08:00
|
|
|
- name: Check RHEL subscription-manager status
|
|
|
|
command: /sbin/subscription-manager status
|
|
|
|
register: rh_subscription_status
|
2023-05-03 03:00:16 +08:00
|
|
|
changed_when: "rh_subscription_status.rc != 0"
|
2021-07-12 15:00:47 +08:00
|
|
|
ignore_errors: true # noqa ignore-errors
|
2020-11-25 00:33:00 +08:00
|
|
|
become: true
|
|
|
|
|
|
|
|
- name: RHEL subscription Organization ID/Activation Key registration
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.redhat_subscription:
|
2020-11-25 00:33:00 +08:00
|
|
|
state: present
|
|
|
|
org_id: "{{ rh_subscription_org_id }}"
|
|
|
|
activationkey: "{{ rh_subscription_activation_key }}"
|
|
|
|
force_register: true
|
|
|
|
notify: RHEL auto-attach subscription
|
|
|
|
become: true
|
|
|
|
when:
|
|
|
|
- rh_subscription_org_id is defined
|
|
|
|
- rh_subscription_status.changed
|
|
|
|
|
2021-07-12 15:00:47 +08:00
|
|
|
# this task has no_log set to prevent logging security sensitive information such as subscription passwords
|
2020-11-25 00:33:00 +08:00
|
|
|
- name: RHEL subscription Username/Password registration
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.redhat_subscription:
|
2020-11-25 00:33:00 +08:00
|
|
|
state: present
|
|
|
|
username: "{{ rh_subscription_username }}"
|
|
|
|
password: "{{ rh_subscription_password }}"
|
|
|
|
auto_attach: true
|
|
|
|
force_register: true
|
|
|
|
syspurpose:
|
|
|
|
usage: "{{ rh_subscription_usage }}"
|
|
|
|
role: "{{ rh_subscription_role }}"
|
|
|
|
service_level_agreement: "{{ rh_subscription_sla }}"
|
|
|
|
sync: true
|
|
|
|
notify: RHEL auto-attach subscription
|
|
|
|
become: true
|
2023-07-05 11:36:54 +08:00
|
|
|
no_log: "{{ not (unsafe_show_logs | bool) }}"
|
2020-11-25 00:33:00 +08:00
|
|
|
when:
|
|
|
|
- rh_subscription_username is defined
|
|
|
|
- rh_subscription_status.changed
|
|
|
|
|
2021-01-25 19:12:54 +08:00
|
|
|
# container-selinux is in extras repo
|
|
|
|
- name: Enable RHEL 7 repos
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.rhsm_repository:
|
2021-01-25 19:12:54 +08:00
|
|
|
name:
|
|
|
|
- "rhel-7-server-rpms"
|
|
|
|
- "rhel-7-server-extras-rpms"
|
2023-04-13 11:04:35 +08:00
|
|
|
state: "{{ 'enabled' if (rhel_enable_repos | default(True) | bool) else 'disabled' }}"
|
2021-01-25 19:12:54 +08:00
|
|
|
when:
|
|
|
|
- ansible_distribution_major_version == "7"
|
2023-05-03 03:00:16 +08:00
|
|
|
- (not rh_subscription_status.changed) or (rh_subscription_username is defined) or (rh_subscription_org_id is defined)
|
2021-01-25 19:12:54 +08:00
|
|
|
|
|
|
|
# container-selinux is in appstream repo
|
|
|
|
- name: Enable RHEL 8 repos
|
2023-06-26 18:15:45 +08:00
|
|
|
community.general.rhsm_repository:
|
2021-01-25 19:12:54 +08:00
|
|
|
name:
|
|
|
|
- "rhel-8-for-*-baseos-rpms"
|
|
|
|
- "rhel-8-for-*-appstream-rpms"
|
2023-04-13 11:04:35 +08:00
|
|
|
state: "{{ 'enabled' if (rhel_enable_repos | default(True) | bool) else 'disabled' }}"
|
2021-01-25 19:12:54 +08:00
|
|
|
when:
|
|
|
|
- ansible_distribution_major_version == "8"
|
2023-05-03 03:00:16 +08:00
|
|
|
- (not rh_subscription_status.changed) or (rh_subscription_username is defined) or (rh_subscription_org_id is defined)
|
2021-01-25 19:12:54 +08:00
|
|
|
|
2020-11-25 00:33:00 +08:00
|
|
|
- name: Check presence of fastestmirror.conf
|
|
|
|
stat:
|
|
|
|
path: /etc/yum/pluginconf.d/fastestmirror.conf
|
2021-02-10 21:36:59 +08:00
|
|
|
get_attributes: no
|
|
|
|
get_checksum: no
|
|
|
|
get_mime: no
|
2020-11-25 00:33:00 +08:00
|
|
|
register: fastestmirror
|
|
|
|
|
|
|
|
# the fastestmirror plugin can actually slow down Ansible deployments
|
|
|
|
- name: Disable fastestmirror plugin if requested
|
|
|
|
lineinfile:
|
|
|
|
dest: /etc/yum/pluginconf.d/fastestmirror.conf
|
|
|
|
regexp: "^enabled=.*"
|
|
|
|
line: "enabled=0"
|
|
|
|
state: present
|
|
|
|
become: true
|
|
|
|
when:
|
|
|
|
- fastestmirror.stat.exists
|
|
|
|
- not centos_fastestmirror_enabled
|
|
|
|
|
|
|
|
# libselinux-python is required on SELinux enabled hosts
|
|
|
|
# See https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#managed-node-requirements
|
|
|
|
- name: Install libselinux python package
|
|
|
|
package:
|
2023-07-05 11:36:54 +08:00
|
|
|
name: "{{ ((ansible_distribution_major_version | int) < 8) | ternary('libselinux-python', 'python3-libselinux') }}"
|
2020-11-25 00:33:00 +08:00
|
|
|
state: present
|
|
|
|
become: true
|