WebQube
WebQube

Reputation: 8961

chef execute bash command and enter input

I want to execute this command via chef :

knife client delete client_name

The command indeed runs from chef using this :

bash 'delete client from chef server' do
    cwd ::File.dirname('/apps/chef-repo') # not sure if relevant
    code <<-EOH
        knife client delete client_name
    EOH
  end

But knife requires confirmation input

STDOUT: Do you really want to client_name? (Y/N)

How do I execute clicking 'Y'?

Upvotes: 0

Views: 571

Answers (3)

coderanger
coderanger

Reputation: 54211

The other two answers are correct in a direct sense, but there is no reason to shell out to knife like this. You can use Chef's HTTP client directly:

node.chef_server_rest.delete_rest('/clients/client_name')

(I think, been a while)

Upvotes: 0

Henk Langeveld
Henk Langeveld

Reputation: 8446

Check the Knife common options:

-y, --yes

Respond to all confirmation prompts with “Yes”. knife is not to ask for confirmation.

Upvotes: 1

Bleys
Bleys

Reputation: 99

You're looking for -y (say yes to confirmation prompts). i.e.

 knife client delete client_name -y

Upvotes: 2

Related Questions