Need a hand on the split command in Chef / Ruby or a regex...

I am using Chef / Ruby and I am using two environments 0001 and 0002..I have 2 log files that I want to lay down on two nodes on in each environment, so hope I make sense here.  I need to hopefully use split in Ruby to parse the 0001 / 0002 and determine which log file to lay down - one in 0001 and 0002 for the other, here is what I have in the configure.rb file:

environment_id = node[:chef_environment].split()

Log file names:



If I didn't give enough detail pls let me know.
Harper McDonaldAsked:
Who is Participating?
Harper McDonaldAuthor Commented:
nitro_environment_id = node[:chef_environment].split(//).last(4).join

I think I just found it out...
Harper McDonaldAuthor Commented:

the node[:chef_environment].split()

should only return 0001 or 0002 and of course be put into environment_id
Harper McDonaldAuthor Commented:
Getting this now:

irb(main):006:0> log3.split("gryphon_cwis_sdlc_")
=> ["", "0002"]

Just need to remove the [ " and ,  --- any ideas?
Dan CraciunIT ConsultantCommented:
Can you please provide the values of "node[:chef_environment]" and "$" ?

From the manual:
split(pattern=$;, [limit]) → anArray
Divides str into substrings based on a delimiter, returning an array of these substrings.

If pattern is omitted, the value of $; is used. If $; is nil (which is the default), str is split on whitespace as if ` ‘ were specified.
Harper McDonaldAuthor Commented:
Found out experimenting
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.