Chef Solo get user input

这一生的挚爱 提交于 2019-11-27 08:21:43

问题


I don't know why I can't find anything on the interwebs about this.

I basically want to write a recipe that prompts a user for their github username/password, then posts to the github API to add an ssh key.

I'm sure I can prompt a user with normal ruby methods (ie gets) but this doesn't seem natural given all the utilities chef provides.

Can someone tell me a 'chef' way of prompting a user for input to store in vars for later use?

I'd like to first output some instructions for the user to read, then get the username, then password, I guess for safety reasons, the password should not be shown on the console as they type


回答1:


I'd say chef is not made for such user input.

You might use ruby code that is executed during the compile phase of the chef run, but I'd suggest the following:

What about reading it from an environment variable?




回答2:


It feels super dirty, but this actually works. Maybe some things can be tuned so that it feels a bit more clean:

file "/tmp/ans" do
  puts "Enter something useful!"
  content ::STDIN.readline
end

You can apply such a recipe with chef-apply, note that using Vagrant will not work.

Still, I would recommend do it differently. Another way would be to not call chef directly, but through a wrapper script. This could read the data from the user and write it into a json file, which is then given to chef via the -j PATH, --json-attributes PATH parameter (see chef-solo parameters).



来源:https://stackoverflow.com/questions/19754127/chef-solo-get-user-input

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!