bootstrap-host: Create swap without using a failed task

This reverts commit 541f04e546 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
This commit is contained in:
Jesse Pretorius (odyssey4me) 2018-02-10 13:43:53 +00:00 committed by Jesse Pretorius
parent 8224fbcede
commit aad094549e

View File

@ -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: