运行 Chef 食谱中一段代码的适当方式

Appropriate way to run a block of code in Chef recipe

我似乎无法在 Chef 中找到 运行ning 一段 shell 代码的证明。例如,我有一个脚本如下:

for user in `awk -F: '( < 500) {print  }' /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: '( < 500) {print  }' /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。