diff --git a/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml b/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml index 56c9ae7471..8143b6ebb1 100644 --- a/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml +++ b/tests/roles/bootstrap-host/tasks/prepare_loopback_swap.yml @@ -13,48 +13,56 @@ # See the License for the specific language governing permissions and # limitations under the License. -- block: - - name: Check if swap is already enabled - command: grep /openstack/swap.img /proc/swaps +- name: Create swap file + command: "{{ swap_create_command }}" + args: + creates: /openstack/swap.img + register: swap_create + tags: + - swap-file-create - rescue: - - name: Create swap file - command: "{{ swap_create_command }}" - args: - creates: /openstack/swap.img - register: swap_create - tags: - - swap-file-create +- name: Set swap file permissions to 0600 + file: + path: /openstack/swap.img + mode: 0600 + tags: + - swap-permissions - - name: Set swap file permissions to 0600 - file: - path: /openstack/swap.img - mode: 0600 - tags: - - swap-permissions +- name: Format the swap file + command: mkswap /openstack/swap.img + when: swap_create | changed + tags: + - swap-format - - name: Format the swap file - command: mkswap /openstack/swap.img - when: swap_create | changed - tags: - - swap-format +- name: Ensure that the swap file entry is in /etc/fstab + mount: + name: none + src: /openstack/swap.img + fstype: swap + opts: sw + passno: 0 + dump: 0 + state: present + tags: + - swap-fstab - - name: Ensure that the swap file entry is in /etc/fstab - mount: - name: none - src: /openstack/swap.img - fstype: swap - opts: sw - passno: 0 - dump: 0 - state: present - tags: - - swap-fstab - - - name: Bring swap file online - command: swapon /openstack/swap.img - tags: - - swap-online +- name: Bring swap file online + shell: | + return_code=0 + if ! grep /openstack/swap.img /proc/swaps; then + swapon /openstack/swap.img + return_code=2 + fi + exit ${return_code} + register: _set_swap_online + changed_when: _set_swap_online.rc == 2 + failed_when: _set_swap_online.rc not in [0, 2] + # We skip ansible lint testing for this task as it fails with + # ANSIBLE0014 Environment variables don't work as part of command + # which is nonsense. + tags: + - skip_ansible_lint + - swap-online - name: Set system swappiness sysctl: