LoginSignup
21
19

More than 5 years have passed since last update.

Ansibleでswap領域を設定する

Posted at

CentOS 7で動作確認しています。

  • 物理メモリと同等のスワップ領域を設定する
  • 何回実行しても大丈夫

という特長があります。

---
- set_fact:
    swap_file_path: /swapfile
- command: dd if=/dev/zero of={{ swap_file_path }} bs={{ ansible_memtotal_mb }} count=1M
  args:
    creates: '{{ swap_file_path }}'
- file:
    path: '{{ swap_file_path }}'
    mode: '0600'
- command: file {{ swap_file_path }}
  register: swap_file_test
- command: mkswap {{ swap_file_path }}
  when: swap_file_test.stdout.find('swap file') == -1
- command: swapon {{ swap_file_path }}
  when: ansible_swaptotal_mb < 1
- mount:
    name: swap
    src: '{{ swap_file_path }}'
    fstype: swap
    opts: defaults
    passno: '0'
    dump: '0'
    state: present

物理メモリの2倍にしたかったら、 {{ ansible_memtotal_mb }} のところを {{ ansible_memtotal_mb * 2 }} とかにすればいいと思います。

参考文献

21
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
19