add swapfile role

This commit is contained in:
Sergey Malyuk
2025-12-18 10:54:07 +03:00
parent 02d63ac131
commit d27ba46d5b
11 changed files with 216 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
---
- name: Converge
hosts: all
become: true
pre_tasks:
- name: "Update apt cache"
when: ansible_os_family == 'Debian'
ansible.builtin.apt:
update_cache: true
cache_valid_time: 600
roles:
- role: genlab.swapfile
swap_file_path: /swapfile
swap_file_size_mb: 2000
swap_swappiness: 30
swap_file_state: present
swap_test_mode: true

View File

@@ -0,0 +1,29 @@
---
dependency:
name: galaxy
driver:
name: docker
platforms:
- name: ubuntu
image: geerlingguy/docker-${MOLECULE_DISTRO:-ubuntu2204}-ansible:latest
command: ${MOLECULE_DOCKER_COMMAND:-""}
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:rw
cgroupns_mode: host
privileged: true
pre_build_image: true
provisioner:
name: ansible
playbooks:
converge: ${MOLECULE_PLAYBOOK:-converge.yml}
verifier:
name: ansible
lint: |
set -e
yamllint .
ansible-lint .

View File

@@ -0,0 +1,26 @@
---
- name: Verify
hosts: all
gather_facts: false
any_errors_fatal: true
vars:
swapfile_path: "/swapfile"
pre_tasks:
- name: "Ensure 'file' exists"
ansible.builtin.package:
name: [file]
state: present
tasks:
- name: "Check swapfile file type"
register: swapfile_info
changed_when: false
ansible.builtin.command:
cmd: "file {{ swapfile_path }}"
- name: "Verify correct file type"
ansible.builtin.assert:
that: "'swap file' in swapfile_info.stdout"
success_msg: "{{ swapfile_path }}: Indeed, a Linux swap file"
fail_msg: "{{ swapfile_path }}: not a Linux swap file ('{{ swapfile_info.stdout }}')"