2018-05-01 10:16:11 +08:00
|
|
|
---
|
|
|
|
- name: remove unused repositories
|
|
|
|
file:
|
|
|
|
name: '/etc/yum.repos.d/{{ item }}.repo'
|
|
|
|
state: 'absent'
|
2021-01-19 23:35:31 +08:00
|
|
|
loop:
|
2018-05-01 10:16:11 +08:00
|
|
|
- 'CentOS-Debuginfo'
|
|
|
|
- 'CentOS-Media'
|
|
|
|
- 'CentOS-Vault'
|
2021-01-19 23:35:31 +08:00
|
|
|
when: os_security_packages_clean | bool
|
2018-05-01 10:16:11 +08:00
|
|
|
|
|
|
|
- name: get yum-repository-files
|
2021-01-19 23:35:31 +08:00
|
|
|
find:
|
|
|
|
paths: '/etc/yum.repos.d'
|
|
|
|
patterns: '*.repo'
|
2018-05-01 10:16:11 +08:00
|
|
|
register: yum_repos
|
|
|
|
|
2021-01-19 23:35:31 +08:00
|
|
|
# for the 'default([])' see here:
|
|
|
|
# https://github.com/dev-sec/ansible-os-hardening/issues/99 and
|
|
|
|
# https://stackoverflow.com/questions/37067827/ansible-deprecation-warning-for-undefined-variable-despite-when-clause
|
|
|
|
- name: activate gpg-check for yum-repository-files
|
2018-05-01 10:16:11 +08:00
|
|
|
replace:
|
2021-01-19 23:35:31 +08:00
|
|
|
path: '{{ item.path }}'
|
|
|
|
regexp: '^\s*gpgcheck.*'
|
|
|
|
replace: 'gpgcheck=1'
|
|
|
|
mode: '0644'
|
|
|
|
with_items:
|
|
|
|
- '{{ yum_repos.files | default([]) }}'
|
2018-05-01 10:16:11 +08:00
|
|
|
|
2021-01-19 23:35:31 +08:00
|
|
|
# failed_when is needed because by default replace module will fail if the file doesn't exists.
|
|
|
|
# status.rc is only defined if an error accrued and only error code (rc) 257 will be ignored.
|
|
|
|
# All other errors will still be raised.
|
|
|
|
- name: activate gpg-check for config files
|
2018-05-01 10:16:11 +08:00
|
|
|
replace:
|
2021-01-19 23:35:31 +08:00
|
|
|
path: '{{ item }}'
|
|
|
|
regexp: '^\s*gpgcheck\W.*'
|
|
|
|
replace: 'gpgcheck=1'
|
|
|
|
mode: '0644'
|
|
|
|
register: status
|
|
|
|
failed_when: status.rc is defined and status.rc != 257
|
|
|
|
loop:
|
|
|
|
- '/etc/yum.conf'
|
|
|
|
- '/etc/dnf/dnf.conf'
|
|
|
|
- '/etc/yum/pluginconf.d/rhnplugin.conf'
|
2018-05-01 10:16:11 +08:00
|
|
|
|
|
|
|
- name: remove deprecated or insecure packages | package-01 - package-09
|
|
|
|
yum:
|
2021-01-19 23:35:31 +08:00
|
|
|
name: '{{ os_security_packages_list }}'
|
2018-05-01 10:16:11 +08:00
|
|
|
state: 'absent'
|
2021-01-19 23:35:31 +08:00
|
|
|
when: os_security_packages_clean | bool
|