Williams Perdana
Williams Perdana

Reputation: 199

Chef cookbook: automatically type yes if prompted

I'm making a cookbook recipe to clone files from provided repository to the nodes. Here is my recipe:

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

But when I run this chef-client on my node, it returns errors saying:

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.

When I tried to run manually the command, I got this:

[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)?

Is there any way to automatically answer yes when it is prompted, or any command to add the repository to the known hosts automatically ?

*Note: I have registered my node's public key to the repository

Upvotes: 1

Views: 248

Answers (2)

coderanger
coderanger

Reputation: 54211

Use a git resource, or potentially a poise_git resource if you need to support a deploy key. It handles disabling interactive stuff for you.

Upvotes: 2

joy
joy

Reputation: 216

You can write Bash resource for the same.

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

Upvotes: 1

Related Questions