[英]unable to delay the evaluation of code block till run time in chef recipe
[英]Appropriate way to run a block of code in Chef recipe
我似乎找不到在Chef中运行shell代码块的证明。 例如,我下面有一个脚本:
for user in `awk -F: '($3 < 500) {print $1 }' /etc/passwd` ; do
if [ $user != "root" ]; then
usermod -L $user
if [ $user != "sync" ] && [ $user != "shutdown" ] && [ $user != "halt" ];
then
usermod -s /sbin/nologin $user
fi
fi
done
..而且我怀疑运行此程序段的方式如下
bash 'run script' do
code <<-EOH
"for user in `awk -F: '($3 < 500) {print $1 }' /etc/passwd` ; do
if [ $user != "root" ]; then
usermod -L $user
if [ $user != "sync" ] && [ $user != "shutdown" ] && [ $user != "halt" ];
then
usermod -s /sbin/nologin $user
fi
fi
done"
EOH
end
但是我真的不确定此构造是否有效。
您不需要在外面加上多余的""
, <<-EOH ... EOH
已经是一种引号,称为heredoc。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.