如果用户在服务器上还没有密钥,我想运行 ssh-copy-id ,所以我在执行块中有一个 not_if 指令。我已经验证 not_if 命令返回 0,但执行块仍然运行。
execute "add ssh key to #{shortname}" do
not_if cmd # proceed only if server doesn't have this key
command "echo 'If prompted for password it is already in your clipboard and you can just paste it in and hit enter'; ssh-copy-id deploy@#{hostname}"
cmd = "ssh -o 'BatchMode yes' deploy@#{hostname} echo 'test'"
puts cmd
end
drostie:chef-ops (ssh_copy_id)$ ssh -o 'BatchMode yes' deploy@jenkins01.c45477.blueboxgrid.com echo 'test'
test
drostie:chef-ops (ssh_copy_id)$ echo $?
0
有任何想法吗?