From aad094549ecacd1c1f9217e6bfa4286213b4b36e Mon Sep 17 00:00:00 2001 From: "Jesse Pretorius (odyssey4me)" Date: Sat, 10 Feb 2018 13:43:53 +0000 Subject: [PATCH] bootstrap-host: Create swap without using a failed task This reverts commit 541f04e54683547182580ced58adfcdb2c920043 and implements a more targeted solution. Unfortunately this implementation's of a try/rescue system which will always fail the try on a fresh system causes a lot of confusion for anyone new to OSA. When seeing the reported failed task the user thinks something went wrong, even though it was working as designed. The main.yml uses a conditional include for the execution of these tasks only if the current swap available < 1MB. This should be enough to prevent the tasks executing again. If they do execute again, then the task to enable swap is now fully idempotent too, so the reason for the initial implementation is also solved. Change-Id: I7be78780505f14fb1b581d22d4762a34cd2005d8 --- .../tasks/prepare_loopback_swap.yml | 84 ++++++++++--------- 1 file changed, 46 insertions(+), 38 deletions(-) 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: