Chef - 运行 远程 SSH 命令
Chef - running remote SSH commands
我如何使用 Chef 执行 运行 远程 SSH 命令?例如,将以下命令带入配方
ssh -T user@host.com <<'ENDSSH'
cat /etc/*-release
ENDSSH
使用 execute
资源
execute "some_resource" do
command "ssh -T user@host.com <<'ENDSSH'
cat /etc/*-release
ENDSSH"
action :run
end
结果
warning: here-document at line 0 delimited by end-of-file (wanted `ENDSSH')
不过,我还没有尝试将 bash
与 ENDSSH
一起使用。使用 EOT
似乎与使用 bash
资源时预期的外部 EOH
冲突。这是否可以使用 Chef,或者 Mixlib::ShellOut
中的某些内容是否更适合解决 Chef 在使用 HEREDOC
时添加或解析的缩进,我认为这是原因?无论哪种情况,稳定性似乎都值得怀疑。
谢谢!
我认为 @coderanger 在评论中给出了最佳答案 ("you almost certainly shouldn't be doing this with Chef"),但为了完整起见,我相信您的字符串中的换行符没有被正确转义。尝试这样的事情:
execute "some_resource" do
command <<-HEREDOC
ssh -T user@host.com <<\'ENDSSH\'
cat /etc/*-release
ENDSSH
HEREDOC
end
我如何使用 Chef 执行 运行 远程 SSH 命令?例如,将以下命令带入配方
ssh -T user@host.com <<'ENDSSH'
cat /etc/*-release
ENDSSH
使用 execute
资源
execute "some_resource" do
command "ssh -T user@host.com <<'ENDSSH'
cat /etc/*-release
ENDSSH"
action :run
end
结果
warning: here-document at line 0 delimited by end-of-file (wanted `ENDSSH')
不过,我还没有尝试将 bash
与 ENDSSH
一起使用。使用 EOT
似乎与使用 bash
资源时预期的外部 EOH
冲突。这是否可以使用 Chef,或者 Mixlib::ShellOut
中的某些内容是否更适合解决 Chef 在使用 HEREDOC
时添加或解析的缩进,我认为这是原因?无论哪种情况,稳定性似乎都值得怀疑。
谢谢!
我认为 @coderanger 在评论中给出了最佳答案 ("you almost certainly shouldn't be doing this with Chef"),但为了完整起见,我相信您的字符串中的换行符没有被正确转义。尝试这样的事情:
execute "some_resource" do
command <<-HEREDOC
ssh -T user@host.com <<\'ENDSSH\'
cat /etc/*-release
ENDSSH
HEREDOC
end