00_core.ymlΒΆ

---
- name: πŸ“¦ Install '
  include_role:
    name: sys-pip-install
  vars:
    # TODO: switch to the PyPI name 'swap-forge' once it is published
    package_name: "git+{{ SWAPFILE_REPO }}@{{ SWAPFILE_REF }}"
    global_install: true

- name: πŸ”Ž Read the active swap files
  command:
    argv:
      - swapon
      - --show=NAME,TYPE,SIZE
      - --bytes
      - --noheadings
      - --raw
  register: swapfile_active
  changed_when: false
  check_mode: false
  become: true

- name: βœ… Keep the active swapfile that already meets the requested size
  debug:
    msg: >-
      An active swapfile of {{ SWAPFILE_ACTIVE_MATCH | first }} bytes is within
      {{ SWAPFILE_TOLERANCE_PERCENT }}% of the requested {{ SWAPFILE_SIZE }},
      so swap-forge does not run and cannot swapoff it.
  when: SWAPFILE_ACTIVE_MATCH | length > 0

- name: ▢️ Execute create swapfile script
  shell: "{{ SWAPFILE_PKG }} '{{ SWAPFILE_SIZE }}'"
  become: true
  when: SWAPFILE_ACTIVE_MATCH | length == 0

- include_tasks: utils/once/flag.yml