Initial commit
[ta/infra-ansible.git] / roles / bootstrap-host / tasks / prepare_loopback_swap.yml
1 ---
2 # Copyright 2015, Rackspace US, Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 - block:
17     - name: Check if swap is already enabled
18       command: grep /openstack/swap.img /proc/swaps
19
20   rescue:
21     - name: Create swap file
22       command: "{{ swap_create_command }}"
23       args:
24         creates: /openstack/swap.img
25       register: swap_create
26       tags:
27         - swap-file-create
28
29     - name: Set swap file permissions to 0600
30       file:
31         path: /openstack/swap.img
32         mode: 0600
33       tags:
34         - swap-permissions
35
36     - name: Format the swap file
37       command: mkswap /openstack/swap.img
38       when: swap_create | changed
39       tags:
40         - swap-format
41
42     - name: Ensure that the swap file entry is in /etc/fstab
43       mount:
44         name: none
45         src: /openstack/swap.img
46         fstype: swap
47         opts: sw
48         passno: 0
49         dump: 0
50         state: present
51       tags:
52         - swap-fstab
53
54     - name: Bring swap file online
55       command: swapon /openstack/swap.img
56       tags:
57         - swap-online
58
59 - name: Set system swappiness
60   sysctl:
61     name: vm.swappiness
62     value: 10
63     state: present
64   tags:
65     - swap-sysctl