Browse Source
Ensure all servers have a swapfile. Change-Id: I6cd38061ce58d275e98fcbc0f82f946cb4e02554 Signed-off-by: Paul Belanger <pabelanger@redhat.com>changes/36/643136/6
4 changed files with 79 additions and 1 deletions
@ -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 }}" |
@ -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 |
Loading…
Reference in new issue