Skip to content

Commit

Permalink
fix(swap): address specific swap configurations (missing fstab, no de…
Browse files Browse the repository at this point in the history
…fault swap on Flatcar Linux) (#9)

* fix(swap): ensure fstab exists before editing it

Prevent failure on OSes that do not have `/etc/fstab`.

References #8

Signed-off-by: Theo Bob Massard <[email protected]>

* fix(swap): skip swap management for Flatcar

Flatcar does not have any swap configured by default
References #9

Signed-off-by: Theo Bob Massard <[email protected]>
  • Loading branch information
tbobm authored Apr 23, 2021
1 parent 6af0959 commit 27aa145
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
- include_tasks: requirements.yml

- include_tasks: swap.yml
when: ansible_distribution != "Flatcar"
6 changes: 6 additions & 0 deletions tasks/swap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
shell: |
swapoff -a
- name: Ensure fstab exists
stat:
path: /etc/fstab
register: fstab_file

- name: Disable SWAP in fstab
replace:
path: /etc/fstab
regexp: '^([^#].*?\sswap\s+sw\s+.*)$'
replace: '# \1'
when: fstab_file.stat.exists

0 comments on commit 27aa145

Please sign in to comment.