我已经写了下面的代码,如果交换不到位,这工作正常,但一旦交换被创build,如果脚本再次执行,它会导致错误。
我尝试使用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
下面是控制台logindebugging
[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文件> / dev / null”