2011-11-21 100 views
1

我想运行ssh-copy-id如果用户在服务器上没有他们的密钥,那么我在execute块中有一个not_if指令。我已经验证了not_if命令返回0,但执行块仍然运行。厨师:not_if不工作

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 [email protected]#{hostname}" 
    cmd = "ssh -o 'BatchMode yes' [email protected]#{hostname} echo 'test'" 
    puts cmd 
end 

 

drostie:chef-ops (ssh_copy_id)$ ssh -o 'BatchMode yes' [email protected] echo 'test' 
test 
drostie:chef-ops (ssh_copy_id)$ echo $? 
0 

任何想法?

+1

为什么不管理目标节点上的用户ssh密钥,您试图复制它? – jtimberman

回答

0

我猜你的not_if命令在你的主机上成功运行,但内部结果是一个错误代码。

也就是说,ssh运行正常,能够连接,运行你的一个班轮,(它有一个错误),然后ssh成功退出,所以块被运行。

我会第二@ jtimberman的建议(我听说他知道关于厨师的一两件事:)),并旨在通过数据库,角色或环境来管理ssh密钥,具体取决于上下文。

1

尝试在调试中运行它。它会给你更多的信息,说明它为什么认为它应该在每次运行中执行。

chef-client -l debug