copr: enable swap as partition on AWS

This commit is contained in:
Miroslav Suchý 2019-09-20 15:40:22 +02:00 committed by Pierre-Yves Chibon
parent 60d5bacd4f
commit 990f66391b
4 changed files with 32 additions and 46 deletions

View file

@ -32,8 +32,6 @@
vars:
ansible_python_interpreter: /usr/bin/python3
swap_file_path: "/swapfile"
swap_file_size_mb: 1024
tasks:
- include: "create_swap_file.yml"

View file

@ -1,47 +1,21 @@
- name: Create swap file
command: dd if=/dev/zero of={{ swap_file_path }} bs=1024 count={{ swap_file_size_mb }}k
creates="{{ swap_file_path }}"
tags:
- swap.file.create
- name: install enable-swap.service
copy:
src: files/enable-swap.service
dest: /etc/systemd/system/
register: enable-swap_service
- name: install enable-swap.sh
copy:
src: files/enable-swap.sh
dest: /usr/local/sbin/
mode: '0755'
- name: Change swap file permissions
file: path="{{ swap_file_path }}"
owner=root
group=root
mode=0600
tags:
- swap.file.permissions
- name: reload systemd
command: systemctl daemon-reload
when: enable-swap_service.changed
- name: "Check swap file type"
command: file {{ swap_file_path }}
register: swapfile
tags:
- swap.file.mkswap
- name: Make swap file
command: "sudo mkswap {{ swap_file_path }}"
when: swapfile.stdout.find('swap file') == -1
tags:
- swap.file.mkswap
- name: Write swap entry in fstab
mount: name=none
src={{ swap_file_path }}
fstype=swap
opts=sw
passno=0
dump=0
state=present
tags:
- swap.fstab
- name: Mount swap
command: "swapon {{ swap_file_path }}"
when: ansible_swaptotal_mb < 1
tags:
- swap.file.swapon
- name: enable enable-swap.sh
service:
name: enable-swap
state: started
enabled: yes

View file

@ -0,0 +1,11 @@
[Unit]
Description=Enable swap on /dev/xvdb
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/sbin/enable-swap.sh
TimeoutStartSec=0
[Install]
WantedBy=default.target

View file

@ -0,0 +1,3 @@
#!/usr/bin/bash
mkswap /dev/xvdb
swapon /dev/xvdb