【问题标题】:chef: not_if not_working厨师:not_if not_working
【发布时间】:2012-11-24 01:51:09
【问题描述】:

如果用户在服务器上还没有密钥,我想运行 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

有什么想法吗?

【问题讨论】:

  • 为什么不在您尝试复制的目标节点上管理用户 ssh 密钥?

标签: chef-infra chef-recipe


【解决方案1】:

尝试在调试中运行它。它将为您提供更多信息,说明为什么它认为应该在每次运行时执行。

chef-client -l debug

【讨论】:

    【解决方案2】:

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

    即ssh运行正常,能连接,运行你的一个liner,(有错误),然后ssh成功退出,这样block就跑了。

    我会支持@jtimberman 的建议(我听说他对 Chef 了解一两件事 :))并旨在根据上下文通过数据包、角色或环境来管理 ssh 密钥。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-06
      相关资源
      最近更新 更多