Markos Chandras f422da8599 Add support for the openSUSE Leap distributions
Add support for the openSUSE Leap distributions. The security rules
are similar to the RedHat and Ubuntu ones. We also replace
ansible_os_family with ansible_pkg_mgr since the former does not
return consistent results across different SUSE distributions especially
on older Ansible versions.

Change-Id: I20ffe17039bb641aad70d8123f0b7e7417a42cba
2017-06-27 15:43:53 +01:00

172 lines
4.5 KiB
YAML

---
# Copyright 2016, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Add or remove packages based on STIG requirements
package:
name: "{{ stig_packages_rhel7 | selectattr('enabled') | selectattr('state', 'equalto', item) | sum(attribute='packages', start=[]) }}"
state: "{{ item }}"
with_items:
- "{{ stig_packages_rhel7 | selectattr('enabled') | map(attribute='state') | unique | list }}"
tags:
- cat1
- auth
- packages
- services
- V-71897
- V-71967
- V-71969
- V-72067
- V-72077
- V-72213
- V-72233
- V-72301
- V-72307
- name: V-71987 - Clean requirements/dependencies when removing packages (RedHat)
lineinfile:
dest: "{{ pkg_mgr_config }}"
regexp: "^(#)?clean_requirements_on_remove"
line: "clean_requirements_on_remove=1"
state: present
when:
- security_package_clean_on_remove | bool
- ansible_os_family | lower == 'redhat'
tags:
- low
- packages
- V-71987
- name: V-71987 - Clean requirements/dependencies when removing packages (SUSE)
lineinfile:
dest: "{{ pkg_mgr_config }}"
regexp: '^(#)?\s*solver\.cleandepsOnRemove'
line: 'solver.cleandepsOnRemove = true'
state: present
when:
- security_package_clean_on_remove | bool
- ansible_pkg_mgr == 'zypper'
tags:
- low
- packages
- V-71987
- name: V-71987 - Clean requirements/dependencies when removing packages (dpkg)
lineinfile:
dest: /etc/apt/apt.conf.d/security-autoremove
regexp: "^(#)?APT::Get::AutomaticRemove"
line: "APT{{ '::' }}Get{{ '::' }}AutomaticRemove \"0\";"
state: present
create: yes
when:
- security_package_clean_on_remove | bool
- ansible_os_family | lower == 'debian'
tags:
- low
- packages
- V-71987
- name: Check if /etc/yum/yum-cron.conf exists
stat:
path: /etc/yum/yum-cron.conf
check_mode: no
register: yum_cron_config_check
when:
- ansible_os_family | lower == 'redhat'
- ansible_pkg_mgr == 'yum'
tags:
- always
- name: Enable automatic package updates (yum)
lineinfile:
dest: /etc/yum/yum-cron.conf
regexp: "^apply_updates"
line: "apply_updates = yes"
state: present
when:
- ansible_os_family | lower == 'redhat'
- ansible_pkg_mgr == 'yum'
- yum_cron_config_check.stat.exists | bool
- security_rhel7_automatic_package_updates | bool
tags:
- packages
- medium
- V-71999
- name: Check if /etc/dnf/automatic.conf exists
stat:
path: /etc/dnf/automatic.conf
check_mode: no
register: dnf_automatic_config_check
when:
- ansible_os_family | lower == 'redhat'
- ansible_pkg_mgr == 'dnf'
tags:
- always
- name: Enable automatic package updates (dnf)
lineinfile:
dest: /etc/dnf/automatic.conf
regexp: "^apply_updates"
line: "apply_updates = yes"
state: present
when:
- ansible_os_family | lower == 'redhat'
- ansible_pkg_mgr == 'dnf'
- dnf_automatic_config_check.stat.exists | bool
- security_rhel7_automatic_package_updates | bool
tags:
- packages
- medium
- V-71999
- name: Enable dnf-automatic timer for automatic package updates
systemd:
name: dnf-automatic.timer
enabled: yes
state: started
when:
- ansible_os_family | lower == 'redhat'
- ansible_pkg_mgr == 'dnf'
- dnf_automatic_config_check.stat.exists | bool
- security_rhel7_automatic_package_updates | bool
tags:
- packages
- medium
- V-71999
- name: Enable automatic package updates (apt)
copy:
src: 20auto-upgrades
dest: /etc/apt/apt.conf.d/20auto-upgrades
when:
- ansible_os_family | lower == 'debian'
- security_rhel7_automatic_package_updates | bool
tags:
- packages
- cat2
- V-71999
- name: Enable automatic package updates (SUSE)
copy:
src: zypper-autoupdates
dest: /etc/cron.daily/zypper-autoupdates
when:
- ansible_pkg_mgr == 'zypper'
- security_rhel7_automatic_package_updates | bool
tags:
- packages
- cat2
- V-71999