--- - name: Initialize swap space become: true ansible.builtin.command: "blkid {{item}}" loop: "{{ base_swap_partitions | default([]) }}" register: blkid - name: Swap devices without swap filesystems present become: true ansible.builtin.command: "mkswap --verbose {{item.item}}" loop: "{{ blkid.results | rejectattr('stdout', 'contains', 'TYPE=\"swap\"') }}" register: mkswap