Chef cookbook:如果出现提示,则自动键入yes

时间:2018-04-09 08:41:58

标签: ssh chef

我正在制作食谱配方,将文件从提供的存储库克隆到节点。这是我的食谱:

execute 'clone files from stash' do
     command 'git clone <REPOSITORY_DIR> /var/www'
end

但是当我在节点上运行此chef-client时,它会返回错误:

Expected process to exit with [0], but received '128'
---- Begin output of git clone [REPOSITORY_URL] /var/www ----
STDOUT: Cloning into '/var/www'...
STDERR: Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

当我尝试手动运行命令时,我得到了这个:

[root@wwwblibli /]# git clone REPO_URL /var/www
Cloning into '/var/www'...
The authenticity of host '[REPO_URL]:8000 ([REPO_IP]:7999)' can't be established.
RSA key fingerprint is xxxx.
RSA key fingerprint is xxxx.
Are you sure you want to continue connecting (yes/no)?

有没有办法在提示时自动回答yes,或者是否自动将存储库添加到已知主机的任何命令?

*注意:我已将节点的公钥注册到存储库

2 个答案:

答案 0 :(得分:2)

如果您需要支持部署密钥,请使用git资源或可能是poise_git资源。它会为您处理禁用交互式内容。

答案 1 :(得分:1)

您可以为此编写Bash资源。

bash 'clone files from stash' do
  user 'root'
  code <<-EOF
  git clone <REPOSITORY_DIR> /var/www
  expect "Are you sure you want to continue connecting "
  send "yes\r"
  expect eof'
  EOF
end