copr: enable swap as partition on AWS
This commit is contained in:
parent
60d5bacd4f
commit
990f66391b
4 changed files with 32 additions and 46 deletions
|
@ -32,8 +32,6 @@
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
swap_file_path: "/swapfile"
|
|
||||||
swap_file_size_mb: 1024
|
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- include: "create_swap_file.yml"
|
- include: "create_swap_file.yml"
|
||||||
|
|
|
@ -1,47 +1,21 @@
|
||||||
- name: Create swap file
|
- name: install enable-swap.service
|
||||||
command: dd if=/dev/zero of={{ swap_file_path }} bs=1024 count={{ swap_file_size_mb }}k
|
copy:
|
||||||
creates="{{ swap_file_path }}"
|
src: files/enable-swap.service
|
||||||
tags:
|
dest: /etc/systemd/system/
|
||||||
- swap.file.create
|
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
|
- name: reload systemd
|
||||||
file: path="{{ swap_file_path }}"
|
command: systemctl daemon-reload
|
||||||
owner=root
|
when: enable-swap_service.changed
|
||||||
group=root
|
|
||||||
mode=0600
|
|
||||||
tags:
|
|
||||||
- swap.file.permissions
|
|
||||||
|
|
||||||
|
- name: enable enable-swap.sh
|
||||||
- name: "Check swap file type"
|
service:
|
||||||
command: file {{ swap_file_path }}
|
name: enable-swap
|
||||||
register: swapfile
|
state: started
|
||||||
tags:
|
enabled: yes
|
||||||
- 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
|
|
||||||
|
|
11
roles/copr/backend/files/provision/files/enable-swap.service
Normal file
11
roles/copr/backend/files/provision/files/enable-swap.service
Normal 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
|
3
roles/copr/backend/files/provision/files/enable-swap.sh
Normal file
3
roles/copr/backend/files/provision/files/enable-swap.sh
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#!/usr/bin/bash
|
||||||
|
mkswap /dev/xvdb
|
||||||
|
swapon /dev/xvdb
|
Loading…
Add table
Add a link
Reference in a new issue