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:
Paul Belanger 2019-03-13 13:21:07 -04:00
parent f69b6d922d
commit 6f7db58426
4 changed files with 79 additions and 1 deletions

View 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 }}"

View 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

View File

@ -19,6 +19,10 @@
include_role: include_role:
name: users name: users
- name: Setup swap role
include_role:
name: swap
- name: Setup openstack.virtualenv role - name: Setup openstack.virtualenv role
include_role: include_role:
name: openstack.virtualenv name: openstack.virtualenv

View File

@ -13,7 +13,7 @@ whitelist_externals = bash
commands = commands =
yamllint -s . yamllint -s .
flake8 flake8
bash -c "ansible-lint -x 405 playbooks/*/*.yaml" bash -c "ansible-lint -x 405 -x 306 playbooks/*/*.yaml"
[testenv:venv] [testenv:venv]
basepython = python3 basepython = python3