Hi,
How to prompt in chef attributes ?
I need to ask from a user whether they need to keep the default value
which i described in attribute file or they need to override with their
new value and get and process in that value itself.
I used get.chomp in ruby_block
#!/usr/bin/ruby
require 'rubygems'
ruby_block "Transfer bits" do
puts node['trans']['host']
block do
HOST = node['trans']['host']
puts HOST
puts "User need to override"
ip1 = gets.chomp
if ip1 == "y" || ip1 == "Y"
puts "Enter ur ip"
ip2 = gets.chomp
puts ip2
else
puts HOST
end
end
end
Like this but it shows:
Errno::ENOENT
172.16.1.121
172.16.1.121 -------------
172.16.1.121
172.16.1.121 No such file or directory - -o
172.16.1.121
172.16.1.121
172.16.1.121
172.16.1.121
172.16.1.121 Cookbook Trace:
172.16.1.121
172.16.1.121 ---------------
172.16.1.121
172.16.1.121 /var/chef/cache/cookbooks/trans/recipes/default.rb:166:in `gets'
172.16.1.121
172.16.1.121 /var/chef/cache/cookbooks/trans/recipes/default.rb:166:in `gets'
172.16.1.121
172.16.1.121 /var/chef/cache/cookbooks/trans/recipes/default.rb:166:in `block (2 levels) in from_file'
172.16.1.121
172.16.1.121
172.16.1.121
172.16.1.121
#!/usr/bin/ruby
require 'rubygems'
ruby_block "Transfer bits" do
puts node['trans']['host']
block do
HOST = node['trans']['host']
puts HOST
puts "User need to override"
ip1 = gets.chomp
if ip1 == "y" || ip1 == "Y"
puts "Enter ur ip"
ip2 = gets.chomp
puts ip2
else
puts HOST
end
end
end
Like this but it shows:
Errno::ENOENT
172.16.1.121
172.16.1.121 -------------
172.16.1.121
172.16.1.121 No such file or directory - -o
172.16.1.121
172.16.1.121
172.16.1.121
172.16.1.121
172.16.1.121 Cookbook Trace:
172.16.1.121
172.16.1.121 ---------------
172.16.1.121
172.16.1.121 /var/chef/cache/cookbooks/trans/recipes/default.rb:166:in `gets'
172.16.1.121
172.16.1.121 /var/chef/cache/cookbooks/trans/recipes/default.rb:166:in `gets'
172.16.1.121
172.16.1.121 /var/chef/cache/cookbooks/trans/recipes/default.rb:166:in `block (2 levels) in from_file'
172.16.1.121
172.16.1.121
172.16.1.121
172.16.1.121
Thanks,
Indra K