Parsing Casandra.yaml in Ruby/Inspec to get seeds value

124 Views Asked by At

How do I parse the following yaml from Cassandra.yaml in Ruby (InSpec) profile to get the seeds value. I would to get all the 3 Ipaddress in one sting or the 3 IP addresses in 3 strings.

seed_provider:

- class_name: org.apache.cassandra.locator.SimpleSeedProvider

  parameters:

      # seeds is actually a comma-delimited list of addresses.

      # Ex: "<ip1>,<ip2>,<ip3>"

      - seeds: "10.0.0.1, 10.0.0.2, 10.0.0.3"
2

There are 2 best solutions below

0
On

Maybe there are better ways, but this would work:

require 'yaml'

config = YAML.load_file("/path/cassandra.yml")[0]
config.dig("parameters").first['seeds']
# => "10.0.0.1, 10.0.0.2, 10.0.0.3"
0
On

You could try the file resource or yaml resource in InSpec.