Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prompt during Chef provision

Part of a Chef cookbook I'm writing is configuring perforce, which requires the user to enter their password (lest they save this in plaintext in an "attributes" file). Is it possible to interrupt the provisioning with an interactive prompt?

like image 263
giraffe Avatar asked Mar 19 '23 21:03

giraffe


1 Answers

We would prompt the user from the Vagrantfile and then set that value as a Chef attribute. Prompts really only makes sense on dev boxes, so they really shouldn't be part of the Chef recipe:

Vagrant.configure('2') do |config|
  config.vm.provision :chef_client do |chef|
    chef.add_role 'dev'
    chef.chef_server_url = 'https://api.opscode.com/organizations/myorg'
    chef.node_name = "vagrant-#{ENV['USER']}-dev.example.com"
    chef.validation_key_path = 'example-validator'
    chef.json = {
      'mysvc' => {
        'password' => MySvc.password()
      }
    }
  end
end

module MySvc
  def self.password
    begin
      system 'stty -echo'
      print 'MySvc Password: '
      ; pass = $stdin.gets.chomp; puts "\n"
    ensure
      system 'stty echo'
    end
    pass
  end
end
like image 196
Sneal Avatar answered Mar 25 '23 04:03

Sneal