diff --git a/galaxy.yml b/galaxy.yml index 0ca231d..8e53bec 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: damex name: systemd -version: 1.0.2 +version: 1.0.3 readme: README.md authors: - Roman Kuzmitskii diff --git a/roles/systemd_oomd/README.md b/roles/systemd_oomd/README.md new file mode 100644 index 0000000..e69de29 diff --git a/roles/systemd_oomd/defaults/main.yml b/roles/systemd_oomd/defaults/main.yml new file mode 100644 index 0000000..e367857 --- /dev/null +++ b/roles/systemd_oomd/defaults/main.yml @@ -0,0 +1,9 @@ +--- +systemd_oomd_service_name: systemd-oomd +systemd_oomd_configuration_file: /etc/systemd/oomd.conf +systemd_oomd_swapusedlimit: 90% +systemd_oomd_defaultmemorypressurelimit: 60% +systemd_oomd_defaultmemorypressuredurationsec: 30s +systemd_oomd_package_name: systemd-oomd +systemd_oomd_package_version: "" +systemd_oomd_package_state: present diff --git a/roles/systemd_oomd/meta/argument_specs.yml b/roles/systemd_oomd/meta/argument_specs.yml new file mode 100644 index 0000000..1e1bc6f --- /dev/null +++ b/roles/systemd_oomd/meta/argument_specs.yml @@ -0,0 +1,26 @@ +--- +argument_specs: + main: + options: + systemd_oomd_service_name: + required: true + type: str + systemd_oomd_configuration_file: + required: true + type: str + systemd_oomd_swapusedlimit: + type: str + systemd_oomd_defaultmemorypressurelimit: + type: str + systemd_oomd_defaultmemorypressuredurationsec: + type: str + systemd_oomd_package_name: + required: true + type: str + systemd_oomd_package_version: + type: str + systemd_oomd_package_state: + type: str + choices: + - present + - absent diff --git a/roles/systemd_oomd/meta/main.yml b/roles/systemd_oomd/meta/main.yml new file mode 100644 index 0000000..abf66b3 --- /dev/null +++ b/roles/systemd_oomd/meta/main.yml @@ -0,0 +1,15 @@ +--- +galaxy_info: + author: Roman Kuzmitskii + description: systemd oomd role + license: GPLv2 + min_ansible_version: 2.16.0 + platforms: + - name: Debian + versions: + - buster + - bullseye + - name: Ubuntu + versions: + - focal +dependencies: [] diff --git a/roles/systemd_oomd/tasks/main.yml b/roles/systemd_oomd/tasks/main.yml new file mode 100644 index 0000000..5b4dd0c --- /dev/null +++ b/roles/systemd_oomd/tasks/main.yml @@ -0,0 +1,13 @@ +--- +- name: Ensure systemd oomd + tags: + - systemd_oomd + - systemd + - oomd + block: + - name: Ensure systemd oomd package + ansible.builtin.import_tasks: package.yml + - name: Ensure systemd oomd oomd.conf + ansible.builtin.import_tasks: oomd.conf.yml + - name: Ensure systemd oomd systemd service + ansible.builtin.import_tasks: systemd_service.yml diff --git a/roles/systemd_oomd/tasks/oomd.conf.yml b/roles/systemd_oomd/tasks/oomd.conf.yml new file mode 100644 index 0000000..11aa041 --- /dev/null +++ b/roles/systemd_oomd/tasks/oomd.conf.yml @@ -0,0 +1,10 @@ +--- +- name: Ensure oomd.conf + ansible.builtin.template: + src: oomd.conf.j2 + dest: "{{ systemd_oomd_configuration_file }}" + group: root + owner: root + mode: "0644" + register: systemd_oomd_conf + become: true diff --git a/roles/systemd_oomd/tasks/package.yml b/roles/systemd_oomd/tasks/package.yml new file mode 100644 index 0000000..a48eb91 --- /dev/null +++ b/roles/systemd_oomd/tasks/package.yml @@ -0,0 +1,9 @@ +--- +- name: Ensure systemd oomd package + ansible.builtin.include_role: + name: damex.apt.apt_packages + vars: + apt_packages: # noqa: var-naming[no-role-prefix] + - name: "{{ systemd_oomd_package_name }}" + version: "{{ systemd_oomd_package_version }}" + state: "{{ systemd_oomd_package_state }}" diff --git a/roles/systemd_oomd/tasks/systemd_service.yml b/roles/systemd_oomd/tasks/systemd_service.yml new file mode 100644 index 0000000..9472853 --- /dev/null +++ b/roles/systemd_oomd/tasks/systemd_service.yml @@ -0,0 +1,7 @@ +--- +- name: Ensure systemd service {{ systemd_oomd_service_name }} + ansible.builtin.include_role: + name: damex.systemd.systemd_service + vars: + systemd_service_name: "{{ systemd_oomd_service_name }}" + systemd_service_restart_on: "{{ systemd_oomd_conf.changed }}" diff --git a/roles/systemd_oomd/templates/oomd.conf.j2 b/roles/systemd_oomd/templates/oomd.conf.j2 new file mode 100644 index 0000000..cc399a1 --- /dev/null +++ b/roles/systemd_oomd/templates/oomd.conf.j2 @@ -0,0 +1,5 @@ +{{ ansible_managed | comment }} +[OOM] +SwapUsedLimit = {{ systemd_oomd_swapusedlimit }} +DefaultMemoryPressureLimit = {{ systemd_oomd_defaultmemorypressurelimit }} +DefaultMemoryPressureDurationSec = {{ systemd_oomd_defaultmemorypressuredurationsec }}