Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap file deletion #2462

Open
vogll opened this issue Dec 9, 2023 · 0 comments
Open

Swap file deletion #2462

vogll opened this issue Dec 9, 2023 · 0 comments

Comments

@vogll
Copy link

vogll commented Dec 9, 2023

Hi,

I was trying to delete file(s) within debops.swapfile role . I have used suggested format of the variable, here is my playbook :

    - name: Remove swap files
      include_role:
        name: swapfile
      vars:
        ansible_system_capabilities_enforced: False
        swapfile__files:
          - path: /swap01
            state: absent

But I can't do this because that this task in the role was always true, turn on the swap and prevent it from being deleted. Here is the snip :

- name: Enable swap files
  command: 'swapon -p {{ item.item.priority | d(swapfile__priority) }} {{ item.item.path | d(item.item) }}'  # noqa no-handler
  with_items: '{{ swapfile__register_allocation.results|d([]) }}'
  when: (item is changed and 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 guess the problem is in the condition. The right prefix item.item.state is missing. My proposal :

- name: Enable swap files
  command: 'swapon -p {{ item.item.priority | d(swapfile__priority) }} {{ item.item.path | d(item.item) }}'  # noqa no-handler
  with_items: '{{ swapfile__register_allocation.results|d([]) }}'
  when: (item is changed and item.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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant