swapfile/tasks/main.yaml
changeset 230 07f08cc98da0
equal deleted inserted replaced
229:7e3bf48e516a 230:07f08cc98da0
       
     1 ---
       
     2 
       
     3 - name: check if swap file exists
       
     4   stat:
       
     5     path: "{{swapfile_path}}"
       
     6   register: swapfile_check
       
     7 
       
     8 - name: create swap file
       
     9   become: yes
       
    10   command: "fallocate -l {{swapfile_size}} {{swapfile_path}}"
       
    11   when: not swapfile_check.stat.exists
       
    12 
       
    13 - name: set swap file permissions
       
    14   become: yes
       
    15   file:
       
    16     path: "{{swapfile_path}}"
       
    17     mode: "0600"
       
    18 
       
    19 - name: format swap file
       
    20   become: yes
       
    21   command: "mkswap {{swapfile_path}}"
       
    22   when: not swapfile_check.stat.exists
       
    23 
       
    24 - name: write swap entry in fstab
       
    25   become: yes
       
    26   mount:
       
    27     name: "none"
       
    28     src: "{{swapfile_path}}"
       
    29     fstype: "swap"
       
    30     opts: "sw"
       
    31     passno: 0
       
    32     dump: 0
       
    33     state: "present"
       
    34 
       
    35 - name: turn on swap
       
    36   become: yes
       
    37   command: "swapon {{swapfile_path}}"
       
    38   when: not swapfile_check.stat.exists