Create swapfile for bootstrap playbook
Ensure all servers have a swapfile. Change-Id: I6cd38061ce58d275e98fcbc0f82f946cb4e02554 Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
f69b6d922d
commit
6f7db58426
20
playbooks/bootstrap/roles/swap/defaults/main.yaml
Normal file
20
playbooks/bootstrap/roles/swap/defaults/main.yaml
Normal file
@ -0,0 +1,20 @@
|
||||
# Copyright 2019 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
---
|
||||
swap_file_group: root
|
||||
swap_file_mode: 0600
|
||||
swap_file_owner: root
|
||||
swap_file_path: /root/swapfile
|
||||
|
||||
swap_size_mb: "{{ ansible_memtotal_mb * 2 }}"
|
54
playbooks/bootstrap/roles/swap/tasks/main.yaml
Normal file
54
playbooks/bootstrap/roles/swap/tasks/main.yaml
Normal file
@ -0,0 +1,54 @@
|
||||
# Copyright 2019 Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
---
|
||||
- name: Create swapfile
|
||||
become: true
|
||||
command: "fallocate -l {{ swap_size_mb }}M {{ swap_file_path }}"
|
||||
args:
|
||||
creates: "{{ swap_file_path }}"
|
||||
|
||||
- name: Ensure swapfile permissions
|
||||
become: true
|
||||
file:
|
||||
group: "{{ swap_file_group }}"
|
||||
mode: "{{ swap_file_mode }}"
|
||||
owner: "{{ swap_file_owner }}"
|
||||
path: "{{ swap_file_path }}"
|
||||
|
||||
- name: Register swap status
|
||||
shell: "swapon -s | grep {{ swap_file_path }}"
|
||||
changed_when: false
|
||||
failed_when: _swap_status.rc > 1
|
||||
register: _swap_status
|
||||
|
||||
- name: Format swapfile
|
||||
become: true
|
||||
command: "mkswap {{ swap_file_path }}"
|
||||
when: not _swap_status.stdout
|
||||
|
||||
- name: Add swapfile to fstab
|
||||
become: true
|
||||
mount:
|
||||
path: swap
|
||||
src: "{{ swap_file_path }}"
|
||||
fstype: swap
|
||||
opts: defaults
|
||||
passno: 0
|
||||
dump: 0
|
||||
state: present
|
||||
|
||||
- name: Enable swapfile
|
||||
become: true
|
||||
command: swapon -a
|
||||
changed_when: false
|
@ -19,6 +19,10 @@
|
||||
include_role:
|
||||
name: users
|
||||
|
||||
- name: Setup swap role
|
||||
include_role:
|
||||
name: swap
|
||||
|
||||
- name: Setup openstack.virtualenv role
|
||||
include_role:
|
||||
name: openstack.virtualenv
|
||||
|
Loading…
Reference in New Issue
Block a user