#!/usr/bin/env ruby require 'yaml' path_to_nodes_pp = ARGV[0] file_content = File.read(File.expand_path(path_to_nodes_pp)) nodes = {} file_content.scan(/(^|\n)node ([^\s]+) ?\{([^}]+)\n(\s+)?\}/).each do |node| name = node[1] includes = node[2].delete("\n").split(/\s+include\s+/).select { |x| !x.empty? }.compact nodes[name] = includes end # nodes.each { |k, v| puts "#{k} => [#{v.join(', ')}]" } rules = [] nodes.each do |name, roles_and_profiles| rule = {} if name =~ %r{^/.+/$} rule[:statement] = "Fact[\"certname\"] LIKE \"#{name}\"" else rule[:statement] = "Fact[\"certname\"] = \"#{name.gsub(/(^['"]|['"]$)/, '')}\"" end rule[:success] = { add: roles_and_profiles } rules << rule end puts rules.to_yaml