Skip to content

Commit

Permalink
Add role prefix to variables for the swap role
Browse files Browse the repository at this point in the history
This resolves the var-naming[no-role-prefix] warning from ansible-lint.
  • Loading branch information
mcdonnnj committed Apr 5, 2024
1 parent 72a048a commit bb27952
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions ansible/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
- cyhy_commander
- role: swap
vars:
swapfile_size: 2GiB
swap_swapfile_size: 2GiB
- cyhy_logrotate

- name: Configure nmap scanning hosts
Expand All @@ -69,7 +69,7 @@
roles:
- role: swap
vars:
swapfile_size: 4GiB
swap_swapfile_size: 4GiB

- name: Configure cyhy-runner hosts
hosts: cyhy_runner
Expand Down
4 changes: 2 additions & 2 deletions ansible/roles/swap/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
---
swapfile_location: /swapfile
swapfile_size: 2GiB
swap_swapfile_location: /swapfile
swap_swapfile_size: 2GiB
12 changes: 6 additions & 6 deletions ansible/roles/swap/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,25 @@

- name: Allocate swapfile
ansible.builtin.command:
cmd: "fallocate --length {{ swapfile_size }} {{ swapfile_location }}"
creates: "{{ swapfile_location }}"
cmd: "fallocate --length {{ swap_swapfile_size }} {{ swap_swapfile_location }}"
creates: "{{ swap_swapfile_location }}"
register: swap_allocate_swapfile

- name: Set swapfile permissions
ansible.builtin.file:
mode: 0600
path: "{{ swapfile_location }}"
path: "{{ swap_swapfile_location }}"

- name: Create swapfile
ansible.builtin.command: # noqa no-handler
cmd: mkswap {{ swapfile_location }}
cmd: mkswap {{ swap_swapfile_location }}
changed_when: swap_create_swapfile.rc == 0
register: swap_create_swapfile
when: swap_allocate_swapfile is changed

- name: Enable swapfile
ansible.builtin.command: # noqa no-handler
cmd: swapon {{ swapfile_location }}
cmd: swapon {{ swap_swapfile_location }}
changed_when: swap_enable_swapfile.rc == 0
register: swap_enable_swapfile
when: swap_create_swapfile is changed
Expand All @@ -35,5 +35,5 @@
fstype: swap
name: none
opts: sw
src: "{{ swapfile_location }}"
src: "{{ swap_swapfile_location }}"
state: present

0 comments on commit bb27952

Please sign in to comment.