public-health-ch/ansible/roles/dev-sec.os-hardening/tasks/sysctl.yml

70 lines
2.2 KiB
YAML
Raw Normal View History

2017-04-24 12:22:51 +00:00
---
- name: protect sysctl.conf
2018-12-17 12:50:15 +00:00
file:
path: '/etc/sysctl.conf'
owner: 'root'
group: 'root'
mode: '0440'
2017-04-24 12:22:51 +00:00
2018-12-17 12:50:15 +00:00
- name: set Daemon umask, do config for rhel-family | NSA 2.2.4.1
template:
src: 'etc/sysconfig/rhel_sysconfig_init.j2'
dest: '/etc/sysconfig/init'
owner: 'root'
group: 'root'
mode: '0544'
when: ansible_distribution == 'RedHat' or ansible_distribution == 'Fedora' or ansible_distribution == 'CentOS' or ansible_distribution == 'Amazon'
2017-04-24 12:22:51 +00:00
- name: install initramfs-tools
2018-12-17 12:50:15 +00:00
apt:
name: 'initramfs-tools'
state: 'present'
update_cache: true
2017-04-24 12:22:51 +00:00
when: ansible_os_family == 'Debian' and os_security_kernel_enable_module_loading
- name: rebuild initramfs with starting pack of modules, if module loading at runtime is disabled
2018-12-17 12:50:15 +00:00
template:
src: 'etc/initramfs-tools/modules.j2'
dest: '/etc/initramfs-tools/modules'
owner: 'root'
group: 'root'
mode: '0440'
2017-04-24 12:22:51 +00:00
when: ansible_os_family == 'Debian' and os_security_kernel_enable_module_loading
register: initramfs
- name: update-initramfs
command: 'update-initramfs -u'
when: initramfs.changed
2018-12-17 12:50:15 +00:00
- name: create a combined sysctl-dict if overwrites are defined
set_fact:
sysctl_config: '{{ sysctl_config | combine(sysctl_overwrite) }}'
when: sysctl_overwrite | default()
2017-04-24 12:22:51 +00:00
- name: Change various sysctl-settings, look at the sysctl-vars file for documentation
sysctl:
name: '{{ item.key }}'
value: '{{ item.value }}'
sysctl_set: yes
state: present
reload: yes
ignoreerrors: yes
with_dict: '{{ sysctl_config }}'
2018-12-17 12:50:15 +00:00
- name: Change various sysctl-settings on rhel6-hosts or older, look at the sysctl-vars file for documentation
2017-04-24 12:22:51 +00:00
sysctl:
name: '{{ item.key }}'
value: '{{ item.value }}'
state: present
reload: yes
ignoreerrors: yes
with_dict: '{{ sysctl_rhel_config }}'
2018-12-17 12:50:15 +00:00
when: ((ansible_distribution == 'RedHat' or ansible_distribution == 'Fedora' or ansible_distribution == 'CentOS') and ansible_distribution_major_version < '7') or ansible_distribution == 'Amazon'
2017-04-24 12:22:51 +00:00
- name: Apply ufw defaults
2018-12-17 12:50:15 +00:00
template:
src: 'etc/default/ufw.j2'
dest: '/etc/default/ufw'
2017-04-24 12:22:51 +00:00
when: ufw_manage_defaults and (ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu')
tags: ufw