• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 104
  • Last Modified:

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:

cwis_sdlc_0001.log

cwis_sdlc_0002.log

If I didn't give enough detail pls let me know.
0
Harper McDonald
Asked:
Harper McDonald
  • 4
1 Solution
 
Harper McDonaldAuthor Commented:
UPDATE:

the node[:chef_environment].split()

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

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

Just need to remove the [ " and ,  --- any ideas?
0
 
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.
0
 
Harper McDonaldAuthor Commented:
nitro_environment_id = node[:chef_environment].split(//).last(4).join

I think I just found it out...
0
 
Harper McDonaldAuthor Commented:
Found out experimenting
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now