[debops.swapfile] Swapfile is disabled after running this role
Nobody has claimed this yet.
- Dominant language
- Jinja
- Stars
- 1.4k
- Forks
- 379
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 8
Description
Before running debops.swapfile:
# free
total used free shared buff/cache available
Mem: 980312 684304 91988 58712 204020 88916
Swap: 4194300 0 4194300
# swapon --show
NAME TYPE SIZE USED PRIO
/swapfile file 4G 9.3M -2
After running debops.swapfile:
# free
total used free shared buff/cache available
Mem: 980312 686972 84020 58712 209320 83616
Swap: 0 0 0
@box:~# swapon --show
I have defined this variable in groups/all.yml:
swapfile__files:
- path: /swapfile
size: 4096
state: present
The file /swapfile already exists as a swapfile and has a size of 4 GiB.
Expected result: no changes.
I think the culprit is in this code:
https://github.com/debops/debops/blob/f66d7db9eea71ad5010010183ca0562ec14f00c4/ansible/roles/swapfile/tasks/main.yml#L8
- name: Disable swap files when requested
ansible.builtin.shell: test -f {{ item.path | d(item) }} && swapoff {{ item.path | d(item) }} || true
changed_when: False
with_items: '{{ swapfile__files }}'
when: (item.state | d("present") == 'absent' and
((ansible_system_capabilities_enforced | d()) | bool and
"cap_sys_admin" in ansible_system_capabilities) or
not (ansible_system_capabilities_enforced | d(True)) | bool)
I see in my logs that it's not skipped:
TASK [debops.debops.swapfile : Disable swap files when requested] **************
task path: /home/runner/.ansible/collections/ansible_collections/debops/debops/roles/swapfile/tasks/main.yml:7
ok: [********] => (item={'path': '/swapfile', 'size': 4096, 'state': 'present'}) => changed=false
ansible_loop_var: item
cmd: test -f /swapfile && swapoff /swapfile || true
delta: '0:00:01.480794'
end: '2025-07-16 12:26:50.457782'
item:
path: /swapfile
size: 4096
state: present
msg: ''
rc: 0
start: '2025-07-16 12:26:48.976988'
stderr: ''
stderr_lines: <omitted>
stdout: ''
stdout_lines: <omitted>
Wednesday 16 July 2025 10:26:50 +0000 (0:00:02.122) 0:00:10.138 ********
Wednesday 16 July 2025 10:26:50 +0000 (0:00:02.122) 0:00:10.136 ********
I would expect it to skip, because item.state == 'present'.
As a workaround, I am adding a post_task to hard enable swap with an unconditional swapon --all.
The host is Ubuntu 22.04.5 LTS.
I am using Debops 3.2.4.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ansible/roles/swapfile/tasks/main.yml, especially the “Disable swap files when requested” task and its condition. Reproduce the role with swapfile__files set to /swapfile in the issue, then verify that a file with state present remains enabled and the task is skipped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ansible
- Domain
- devops, infrastructure
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100