下記ページを参考にしてswapを作った。
https://qiita.com/youcune/items/ae8ba3a53cd91c490ad6
実行時のansibleのバージョンは下記。
$ ansible-playbook --version
ansible-playbook 2.4.1.0
ただし参照先にあるansibleそのままでは動かなかった。
具体的にはansible_swaptotal_mbが未定義のが原因。
なので最終的には下記のようにした。
---
- set_fact:
swap_file_path: /swapfile
- name: zero padding
command: dd if=/dev/zero of={{ swap_file_path }} bs={{ ansible_memtotal_mb }} count=1M
args:
creates: '{{ swap_file_path }}'
- name: make swap file
file:
path: '{{ swap_file_path }}'
mode: '0600'
- name: check file type
command: file {{ swap_file_path }}
register: swap_file_test
- name: mkswap
command: mkswap {{ swap_file_path }}
when: swap_file_test.stdout.find('swap file') == -1
- name: check swap
command: /sbin/swapon -s
register: check_swap
- name: swap on
command: swapon {{ swap_file_path }}
when: check_swap.stdout == ''
- name: mount swap
mount:
name: swap
src: '{{ swap_file_path }}'
fstype: swap
opts: defaults
passno: '0'
dump: '0'
state: present
One Response on “EC2インスタンスにswapを作った話”