Files
chef/site-cookbooks/kosmos_kvm/recipes/guest.rb
T
raucao 098dcd4e32 Auto-configure swap
Create a swapfile and configure it to be used for swap, immediately and
on boot; defaults to half the size of RAM. See attribute for overriding
configs to tune size or swappiness.
2026-08-14 12:10:37 -06:00

28 lines
688 B
Ruby

#
# Cookbook:: kosmos_kvm
# Recipe:: guest
#
package %w(qemu-guest-agent)
service "qemu-guest-agent" do
action [:enable, :start]
end
swap_cfg = node["kosmos_kvm"]["guest"]["swap"]
if swap_cfg["enabled"] && swap_cfg["size_mb"] != 0
size = swap_cfg["size_mb"] ||
(node["memory"]["total"].to_i / 2 / 1024) # kB -> MB, half RAM
# The resource only creates/activates the swapfile if it is not already
# active; an existing active swapfile is left untouched (size is NOT
# reconciled to current RAM).
swap_file swap_cfg["path"] do
size size
persist true
swappiness swap_cfg["swappiness"] if swap_cfg["swappiness"]
action :create
end
end