itamae/cookbooks/base/aws_ec2.rb

27 lines
494 B
Ruby
Raw Normal View History

2019-03-03 08:50:49 +00:00
# Make swap file:
[
'dd if=/dev/zero of=/swap.img bs=1M count=2048 && chmod 600 /swap.img && mkswap /swap.img'
2019-03-03 08:50:49 +00:00
].each do |cmd|
execute cmd do
user 'root'
only_if 'test ! -f /swap.img'
2019-03-03 08:50:49 +00:00
end
end
# Add the fstab entry:
file '/etc/fstab' do
action :edit
block do |content|
content << "/swap.img /dev/null swap defaults 0 2\n"
end
not_if 'grep swap.img /etc/fstab'
end
# Mount the swap file:
execute 'swapon -ae' do
only_if 'test `cat /proc/swaps | wc -l` -eq 1'
end