40b22b6829c888d49ca0cf6d6d83640e2480b58d
[kuberef.git] / sw_config / bmra / patched_rhel_packages.yml
1 # SPDX-FileCopyrightText: 2021 Intel Corporation.
2 #
3 # SPDX-License-Identifier: Apache-2.0
4
5 ---
6 - name: enable PowerTools repository on CentOS >= 8 and < 8.3
7 # noqa 303 - yum is called intenionallly here
8   command: yum config-manager --set-enabled PowerTools
9   when:
10     - ansible_distribution == "CentOS"
11     - ansible_distribution_version >= '8' and ansible_distribution_version < '8.3'
12
13 - name: enable PowerTools repository on CentOS >= 8.3
14 # noqa 303 - yum is called intenionallly here
15   command: yum config-manager --set-enabled powertools
16   when:
17     - ansible_distribution == "CentOS"
18     - ansible_distribution_version >= '8.3'
19
20 - name: enable CodeReady Linux Builder repository on RHEL 8
21   rhsm_repository:
22     name: codeready-builder-for-rhel-8-x86_64-rpms
23   when:
24     - ansible_distribution == "RedHat"
25     - ansible_distribution_version >= '8'
26
27 - name: install epel-release on CentOS
28   package:
29     name: epel-release
30   when:
31     - ansible_distribution == "CentOS"
32
33 - name: obtain EPEL GPG key on RHEL8
34   rpm_key:
35     state: present
36     key: https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-8
37   when:
38     - ansible_distribution == "RedHat"
39     - ansible_distribution_version >= '8'
40
41 - name: install epel-release on RHEL8
42   package:
43     name: https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
44   when:
45     - ansible_distribution == "RedHat"
46     - ansible_distribution_version >= '8'
47
48 - name: get full distribution versions
49   command: cat /etc/redhat-release
50   register: release
51   changed_when: true
52
53 - name: set full distribution version
54   set_fact:
55     full_dist_version: "{{ release.stdout | regex_replace('.*(\\d+.\\d+.\\d\\d\\d\\d).*', '\\1') }}"
56
57 - name: update CentOS Vault yum repository on CentOS 7
58   yum_repository:
59     name: C{{ full_dist_version }}-base
60     description: CentOS-{{ full_dist_version }} - Base
61     file: CentOS-Vault
62     baseurl: http://vault.centos.org/{{ full_dist_version }}/os/$basearch/
63     gpgcheck: yes
64     gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-{{ ansible_distribution_major_version }}
65     enabled: yes
66   when:
67     - ansible_distribution == "CentOS"
68     - ansible_distribution_version < '7.9'
69     - not update_kernel
70
71 #- name: update CentOS Vault yum repository on CentOS 8
72 #  yum_repository:
73 #    name: C{{ full_dist_version }}-base
74 #    description: CentOS-{{ full_dist_version }} - Base
75 #    file: CentOS-Vault
76 #    baseurl: http://vault.centos.org/{{ full_dist_version }}/BaseOS/$basearch/os/
77 #    baseurl: http://vault.centos.org/{{ full_dist_version }}/BaseOS/Source/
78 #    gpgcheck: yes
79 #    gpgkey: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
80 #    enabled: yes
81 #  when:
82 #    - ansible_distribution == "CentOS"
83 #    - ansible_distribution_version >= '8' and ansible_distribution_version < '8.3'
84 #    - not update_kernel
85
86 # CentOS-Vault repo not working for CentOS 8, so install kernel headers directly
87 - name: pull matching kernel headers on CentOS 8.2
88   package:
89     name: "{{ item }}"
90     state: present
91   register: source_status
92   with_items:
93     - "https://vault.centos.org/8.2.2004/BaseOS/x86_64/os/Packages/kernel-headers-4.18.0-193.el8.x86_64.rpm"
94     - "https://vault.centos.org/8.2.2004/BaseOS/x86_64/os/Packages/kernel-devel-4.18.0-193.el8.x86_64.rpm"
95   when:
96     - ansible_distribution == "CentOS"
97     - ansible_distribution_version == '8.2'
98     - not update_kernel
99
100 - name: pull matching kernel headers on CentOS 8.3
101   package:
102     name: "{{ item }}"
103     state: present
104   register: source_status
105   with_items:
106     - "http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/kernel-headers-4.18.0-240.el8.x86_64.rpm"
107     - "http://mirror.centos.org/centos/8/BaseOS/x86_64/os/Packages/kernel-devel-4.18.0-240.el8.x86_64.rpm"
108 #    - "https://vault.centos.org/8.3.2011/BaseOS/x86_64/os/Packages/kernel-headers-4.18.0-240.el8.x86_64.rpm"
109 #    - "https://vault.centos.org/8.3.2011/BaseOS/x86_64/os/Packages/kernel-devel-4.18.0-240.el8.x86_64.rpm"
110   when:
111     - ansible_distribution == "CentOS"
112     - ansible_distribution_version == '8.3'
113     - not update_kernel
114
115 # pull the matching kernel headers if kernel is not updated
116 - name: pull matching kernel headers from configured repos
117 # noqa 503 - more than one condition, can't be a handler
118   package:
119     name:
120     - kernel-headers-{{ ansible_kernel }}
121     - kernel-devel-{{ ansible_kernel }}
122   register: kernel_source
123   retries: 3
124   until: kernel_source is success
125   when:
126     - not source_status.changed
127     - ansible_os_family == "RedHat"
128     - not update_kernel
129
130 - name: install the 'Development tools' package group
131   package:
132     name: "@Development tools"
133   when:
134     - ansible_os_family == "RedHat"
135
136 - name: install pip
137   package:
138     name: python-pip
139   when:
140     - ansible_distribution in ["RedHat", "CentOS"]
141     - ansible_distribution_version < '8'
142
143 - name: install pip
144   package:
145     name: python3-pip
146   when:
147     - ansible_distribution in ["RedHat", "CentOS"]
148     - ansible_distribution_version >= '8'
149
150 - name: update all packages
151   package:
152     name: '*'
153     state: latest # noqa 403
154     exclude: kernel*
155   when:
156     - ansible_os_family == "RedHat"
157     - update_all_packages | default(false)
158
159 - name: update to the latest kernel and kernel headers on the Red Hat OS family
160   package:
161     name:
162     - kernel
163     - kernel-devel
164     state: latest # noqa 403
165   notify:
166     - reboot server
167   when:
168     - ansible_os_family == "RedHat"
169     - update_kernel | default(false)
170
171 #note(przemeklal): fixes issue with missing selinux in packet.net CentOS 7 images
172 - name: ensure selinux is installed on CentOS/RHEL 7
173   package:
174     name:
175     - policycoreutils
176     - policycoreutils-python
177     - selinux-policy
178     - selinux-policy-targeted
179     - libselinux-utils
180     - setools
181     - setools-console
182     - shtool
183     - lshw
184     state: present
185   when:
186     - ansible_distribution in ["RedHat", "CentOS"]
187     - ansible_distribution_version < '8'
188
189 # Workaround for Equinix Metal CentOS 7
190 - name: set selinux to permissive
191   lineinfile:
192     path: "/etc/sysconfig/selinux"
193     regexp: '^SELINUX=enforcing'
194     line: 'SELINUX=permissive'
195   when:
196     - ansible_distribution in ["RedHat", "CentOS"]
197     - ansible_distribution_version < '8'
198
199 - name: Set python is python3
200   alternatives:
201     name: python
202     path: /usr/bin/python3
203     link: /usr/bin/python
204   when:
205     - ansible_distribution == 'CentOS' or ansible_distribution == 'RedHat'
206     - ansible_distribution_version >= '8'
207
208 - name: install command line tools to collect hardware details
209   package:
210     name:
211      - hwinfo
212      - inxi
213      - jq
214     state: present
215   when: ansible_distribution in ["RedHat", "CentOS"]
216
217 - name: use the correct pip version for CentOS 7
218   pip:
219     name:
220       - pip==9.0.3
221   when:
222     - ansible_distribution == "CentOS"
223     - ansible_distribution_version < '7.9'