fix ansible-lint errors

This commit is contained in:
Sergey Malyuk
2025-12-18 11:29:03 +03:00
parent d27ba46d5b
commit ef524d7006
6 changed files with 35 additions and 35 deletions

View File

@@ -1,8 +1,8 @@
--- ---
swap_file_path: /swapfile swapfile_path: /swapfile
swap_file_size_mb: '512' swapfile_size_mb: '512'
swap_swappiness: '60' swapfile_swappiness: '60'
swap_file_state: present swapfile_state: present
swap_file_create_command: "dd if=/dev/zero of={{ swap_file_path }} bs=1M count={{ swap_file_size_mb }}" swapfile_create_command: "dd if=/dev/zero of={{ swapfile_path }} bs=1M count={{ swapfile_size_mb }}"
swap_test_mode: false swapfile_test_mode: false

View File

@@ -10,8 +10,8 @@ galaxy_info:
platforms: platforms:
- name: "Ubuntu" - name: "Ubuntu"
versions: [ "focal", "jammy" ] versions: ["focal", "jammy"]
galaxy_tags: [ ] galaxy_tags: []
dependencies: [] dependencies: []

View File

@@ -11,9 +11,9 @@
cache_valid_time: 600 cache_valid_time: 600
roles: roles:
- role: genlab.swapfile - role: genlab.common.swapfile
swap_file_path: /swapfile swapfile_path: /swapfile
swap_file_size_mb: 2000 swapfile_size_mb: 2000
swap_swappiness: 30 swapfile_swappiness: 30
swap_file_state: present swapfile_state: present
swap_test_mode: true swapfile_test_mode: true

View File

@@ -7,5 +7,5 @@
- name: "Disable | ensure swap file doesn't exist" - name: "Disable | ensure swap file doesn't exist"
ansible.builtin.file: ansible.builtin.file:
path: "{{ swap_file_path }}" path: "{{ swapfile_path }}"
state: absent state: absent

View File

@@ -3,45 +3,45 @@
- name: "Enable | create the swap file" - name: "Enable | create the swap file"
block: block:
- name: "Enable | stat the swap file" - name: "Enable | stat the swap file"
register: this register: swapfile_this
failed_when: not this.stat.exists failed_when: not swapfile_this.stat.exists
ansible.builtin.stat: ansible.builtin.stat:
path: "{{ swap_file_path }}" path: "{{ swapfile_path }}"
get_checksum: false get_checksum: false
get_mime: false get_mime: false
get_attributes: false get_attributes: false
rescue: rescue:
- name: "Enable | ensure swap file exists" - name: "Enable | ensure swap file exists"
register: swap_file_create register: swapfile_create
ansible.builtin.command: ansible.builtin.command:
cmd: "{{ swap_file_create_command }}" cmd: "{{ swapfile_create_command }}"
creates: "{{ swap_file_path }}" creates: "{{ swapfile_path }}"
- name: "Enable | set permissions on swap file" - name: "Enable | set permissions on swap file"
ansible.builtin.file: ansible.builtin.file:
path: "{{ swap_file_path }}" path: "{{ swapfile_path }}"
owner: root owner: root
group: root group: root
mode: "0600" mode: "0600"
- name: "Enable | make swap" # noqa: no-handler no-changed-when - name: "Enable | make swap" # noqa: no-handler no-changed-when
register: mkswap_result register: swapfile_mkswap_result
when: swap_file_create is changed when: swapfile_create is changed
ansible.builtin.command: ansible.builtin.command:
cmd: mkswap {{ swap_file_path }} cmd: mkswap {{ swapfile_path }}
- name: "Enable | run swapon on the swap file => '{{ swap_file_path }}'" - name: "Enable | run swapon on the swap file => '{{ swapfile_path }}'"
when: when:
- mkswap_result is changed - swapfile_mkswap_result is changed
- not swap_test_mode - not swapfile_test_mode
changed_when: false changed_when: false
ansible.builtin.command: ansible.builtin.command:
cmd: swapon {{ swap_file_path }} cmd: swapon {{ swapfile_path }}
- name: "Set swappiness to '{{ swap_swappiness }}'" - name: "Set swappiness to '{{ swapfile_swappiness }}'"
ansible.posix.sysctl: ansible.posix.sysctl:
name: vm.swappiness name: vm.swappiness
value: "{{ swap_swappiness }}" value: "{{ swapfile_swappiness }}"
state: present state: present

View File

@@ -2,17 +2,17 @@
- name: "Manage swap file entry in fstab" - name: "Manage swap file entry in fstab"
ansible.posix.mount: ansible.posix.mount:
name: none name: none
src: "{{ swap_file_path }}" src: "{{ swapfile_path }}"
fstype: swap fstype: swap
opts: sw opts: sw
state: "{{ swap_file_state }}" state: "{{ swapfile_state }}"
- name: "Include disable swap tasks" - name: "Include disable swap tasks"
when: swap_file_state == 'absent' when: swapfile_state == 'absent'
ansible.builtin.include_tasks: disable.yml ansible.builtin.include_tasks: disable.yml
- name: "Include enable swap tasks" - name: "Include enable swap tasks"
when: swap_file_state == 'present' when: swapfile_state == 'present'
ansible.builtin.include_tasks: enable.yml ansible.builtin.include_tasks: enable.yml