devstack-gate/roles/configure-swap/tasks/main.yaml

64 lines
2.2 KiB
YAML

# On RAX hosts, we have a small root partition and a large,
# unallocated ephemeral device attached at /dev/xvde
- name: Set ephemeral device if /dev/xvde exists
when: ansible_devices["xvde"] is defined
set_fact:
ephemeral_device: "/dev/xvde"
# On other providers, we have a device called "ephemeral0".
#
# NOTE(ianw): Once [1] is in our ansible (2.4 era?), we can figure
# this out more directly by walking the device labels in the facts
#
# [1] https://github.com/ansible/ansible/commit/d46dd99f47c0ee5081d15bc5b741e9096d8bfd3e
- name: Set ephemeral device by label
when: ephemeral_device is undefined
block:
- name: Get ephemeral0 device node
command: /sbin/blkid -L ephemeral0
register: ephemeral0
# If this doesn't exist, returns !0
ignore_errors: yes
changed_when: False
- name: Set ephemeral device if LABEL exists
when: "ephemeral0.rc == 0"
set_fact:
ephemeral_device: "{{ ephemeral0.stdout }}"
# If we have ephemeral storage and we don't appear to have setup swap,
# we will create a swap and move /opt to a large data partition there.
- include: ephemeral.yaml
static: no
when:
- ephemeral_device is defined
- ansible_memory_mb['swap']['total'] | int + 10 <= configure_swap_size
# If no ephemeral device and no swap, then we will setup some swap
# space on the root device to ensure all hosts a consistent memory
# environment.
- include: root.yaml
static: no
when:
- ephemeral_device is undefined
- ansible_memory_mb['swap']['total'] | int + 10 <= configure_swap_size
# ensure a standard level of swappiness. Some platforms
# (rax+centos7) come with swappiness of 0 (presumably because the
# vm doesn't come with swap setup ... but we just did that above),
# which depending on the kernel version can lead to the OOM killer
# kicking in on some processes despite swap being available;
# particularly things like mysql which have very high ratio of
# anonymous-memory to file-backed mappings.
#
# This sets swappiness low; we really don't want to be relying on
# cloud I/O based swap during our runs if we can help it
- name: Set swappiness
become: yes
sysctl:
name: vm.swappiness
value: 30
state: present
- debug: var=ephemeral_device