Chef's hint

The part of the cookbook for the chef that I write sets up perforce, for which the user needs to enter their password (so that they do not save this in plain text in the attribute file). Is it possible to interrupt the initialization using the interactive tooltip?

+4
source share
2 answers

Correct me if I misunderstood your problem, if you want to read user input:
You can use the built-in SHELL read command.

example:

[myprompt]$ read -p "Insert text : " IN_TEXT
Insert text : user input
[myprompt]$ echo $IN_TEXT
user input

ps: if you use the read command for the password, you can use the "-s" option to hide the input coming from the terminal.

example2:

[myprompt]$ read -sp "Insert text : " IN_TEXT
Insert text :                                            //stdin <<"user input"
[myprompt]$ echo $IN_TEXT
user input
+3

Vagrantfile, Chef. dev-, -:

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
+3

All Articles