Chef の Guard機能(only_if, not_if)が 1つのリソース内で複数 指定可能、というお話。
周知の事実なのかもだけど、公式マニュアルには書いてない?ようだったので。
Common Functionality: guard
https://docs.chef.io/resource_common.html#guards
only_if と not_if の混在も可能。
最終的に、一個でもskipしちゃうGuard条件があるとSkipされる
[root@vcent01 ~]# cat <<_EOL_ | chef-apply -s
execute "guard test" do
user "root"
command <<-EOM
echo "execute"
EOM
only_if "exit 0"
only_if "exit 0"
end
_EOL_
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* execute[guard test] action run
- execute echo "execute"
[root@vcent01 ~]# cat <<_EOL_ | chef-apply -s
execute "guard test" do
user "root"
command <<-EOM
echo "execute"
EOM
only_if "exit 1" # <- skip
only_if "exit 0"
end
_EOL_
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* execute[guard test] action run (skipped due to only_if) <- skipしちゃった
only_if
と not_if
の混在の例。
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* execute[guard test] action run (skipped due to only_if)
[root@vcent01 ~]# cat <<_EOL_ | chef-apply -s
execute "guard test" do
user "root"
command <<-EOM
echo "execute"
EOM
only_if "exit 0" # <- only_if と not_if の混在も可能
not_if "exit 1"
end
_EOL_
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* execute[guard test] action run
- execute echo "execute"
混在してても最終的には 一個でもskipしちゃうGuard条件があればskip。
[root@vcent01 ~]# cat <<_EOL_ | chef-apply -s
execute "guard test" do
user "root"
command <<-EOM
echo "execute"
EOM
not_if "exit 0" # <- skip
only_if "exit 0"
end
_EOL_
Recipe: (chef-apply cookbook)::(chef-apply recipe)
* execute[guard test] action run (skipped due to not_if) <- skipした