Я написал следующий код, и это хорошо работает, если подкачка не существует, но после того как подкачка создается и если сценарий выполняется снова, это приводит к ошибке.
Я пытался добавить условия с помощью onlyif и если, которые прокомментированы в следующем коде, но ни один из них, кажется, не работает
class swap {
exec { "create swap file":
command => "dd if=/dev/zero of=/swapfile bs=1M count=1024",
path => "/bin/",
creates => "/swapfile",
}
exec { "makeswap":
command => "mkswap /swapfile",
path => "/sbin/",
# condition so that the block is executed only if the swap is not place
onlyif => "/sbin/swapon -s | /bin/grep file > /dev/null",
require => Exec['create swap file'],
}
exec { "enable swap":
command => "swapon /swapfile",
path => "/sbin/",
require => Exec['makeswap'],
}
}
include swap
Ниже консольная отладка входа в систему
[root@puppet testpuppet]# puppet apply swap.pp --debug
...
Debug: Finishing transaction 70032061368300
Debug: Loaded state in 0.00 seconds
Debug: Loaded state in 0.00 seconds
Debug: /Stage[main]/Swap/Exec[makeswap]/require: requires Exec[create swap file]
Debug: /Stage[main]/Swap/Exec[enable swap]/require: requires Exec[makeswap]
Info: Applying configuration version '1404202521'
Debug: Exec[makeswap](provider=posix): Executing check '/sbin/swapon -s | /bin/grep file > /dev/null'
Debug: Executing '/sbin/swapon -s | /bin/grep file > /dev/null'
Debug: Exec[makeswap](provider=posix): Executing 'mkswap /swapfile'
Debug: Executing 'mkswap /swapfile'
Notice: /Stage[main]/Swap/Exec[makeswap]/returns: executed successfully
...
Проблема решена добавлением следующего утверждения в
, если только => "/sbin/swapon -s | /bin/grep file > /dev/null"