LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ruby IF question (https://www.linuxquestions.org/questions/programming-9/ruby-if-question-4175469809/)

szboardstretcher 07-16-2013 09:45 AM

ruby IF question
 
Good morning,

Im working on a chef plugin, that i did not write, and I realize that it needs an IF statement.

Pseduo:
If user root, then home is /root/
else
home is /home/$user

Im not a programmer at all so im not sure how much code to include, but this seems like the important section. Any takers for fixing this snippet for me?

Code:

  user  = params[:name]
  group = params[:group] || user
  home  = params[:home]  || "/home/#{user}"
  keys  = data_bag params[:keys]


JohnGraham 07-16-2013 11:12 AM

Quote:

Originally Posted by szboardstretcher (Post 4991285)
Code:

home  = params[:home]  || "/home/#{user}"

That looks fine, assuming that params won't have a :home key (i.e. params[:home] will be nil) if you don't want to use it. What's wrong with it? I.e. what behavior do you expect from it, and what are you getting instead?

Although note that if you're only dealing with the current user, you should normally just use ENV['HOME'] as their home directory, as that will (i) be easier for you and (ii) cover weird/unusual configurations, and (iii) be nil/the empty string (not sure which) if the user has no home directory configured.

szboardstretcher 07-16-2013 11:23 AM

excellent. thank you for the input.

https://github.com/skalar-cookbooks/authorized_keys

I got the plugin from this place. So i dont understand what its actually doing - except that its automatically assuming roots home folder is /home/root.

I've since found the chef documentation that explains how to distribute ssh keys without plugins here:

https://opscode.app.box.com/shared/b0lmhnhn09

If anyone finds this thread looking for ssh key distribution in chef, this is the guide you will need.


All times are GMT -5. The time now is 01:09 AM.