0

I have site.pp in puppet 3.8 I want to convert site.pp to JSON.

I found https://gist.github.com/atdt/3704340/be33cc0d1671dcbe8c4d4ede4cde3e0953546edf

https://www.gavinmogan.com/2012/03/14/output-pretty-json-puppet

But, i dont know how to convert site.pp to JSON

$commons                                           = hiera('commons', {})

$post_repo_fqdn                                    = $commons['post_repo_fqdn']

$team_frontend_proxy_exclusions = 'localhost|127.0.0.1|10.2.*|*.dev.local|*.local|*-dev.local|*-test.local'
$use_team_frontend_proxy = true
$team_frontend_proxy_host = '10.2.53.213'
$update_history_job_delay_min = 10
$enot_test_mode = true

$team_frontend_web_client_external_url = 'team_frontend-web.local'
$team_frontend_url='https://team_frontend-web.local/help'
$team_frontend_admin_status_timeout = 30000

$returns_ttl = 120

$team_frontend_servers = {
  rest_api => { server_port => $team_frontend['rest_api']['ports'], size => 20 },
  web_app  => { server_port => $team_frontend['webapp']['ports'],   size => 20 },
}

commons.yaml:

commons:
  post_repo_fqdn                 : test-deploy1

if run (https://gist.github.com/atdt/3704340/be33cc0d1671dcbe8c4d4ede4cde3e0953546edf) ruby punch.rb site.pp, then get error:

/usr/share/ruby/vendor_ruby/puppet/resource/type_collection_helper.rb:5:in `known_resource_types': undefined method `known_resource_types' for "":String (NoMethodError)
    from /usr/share/ruby/vendor_ruby/puppet/parser/parser_support.rb:120:in `import'
    from punch.rb:92:in `<main>'

write test ruby script:

test.rb 
require 'json'
require 'pp'

data = File.read("/etc/puppet/environments/team_frontend/manifests/site.pp")

pp ap(JSON.parse(data.to_json))

And get error

/usr/share/ruby/json/common.rb:155:in `parse': 757: unexpected token at '"$commons                                           = hiera('commons', {})\n\n$post_repo_fqdn                                    = $commons['post_repo_fqdn']\n\n$team_frontend_proxy_exclusions = 'localhost|127.0.0.1|10.2.*|*.dev.local|*.local|*-dev.local|*-test.local'\n$use_team_frontend_proxy = true\n$team_frontend_proxy_host = '10.2.53.213'\n$update_history_job_delay_min = 10\n$enot_test_mode = true\n\n$team_frontend_web_client_external_url = 'team_frontend-web.local'\n$team_frontend_url='https://team_frontend-web.local/help'\n$team_frontend_admin_status_timeout = 30000\n\n$returns_ttl = 120\n\n$team_frontend_servers = {\n  rest_api => { server_port => $team_frontend['rest_api']['ports'], size => 20 },\n  web_app  => { server_port => $team_frontend['webapp']['ports'],   size => 20 },\n}\n\n"' (JSON::ParserError)
    from /usr/share/ruby/json/common.rb:155:in `parse'
    from test.rb:6:in `<main>'

How convert puppet site.pp to json? Thanks for commented. I want to migrate from puppet variable to consul kv.

Thanks!

John Bollinger
  • 160,171
  • 8
  • 81
  • 157
Anton Patsev
  • 605
  • 2
  • 13
  • 27
  • It's unclear what manner of transformation you want to perform, for there is no clear mapping directly from Puppet DSL to JSON. Do you mean you want to generate a Puppet catalog, and express *that* in JSON format? Such an endeavor often involves multiple files, and it is not well categorized as a conversion. – John Bollinger Jul 25 '19 at 23:11
  • Thanks for commented. I want to migrate from puppet variable to consul kv. – Anton Patsev Jul 26 '19 at 05:05
  • Ok, I have added appropriate tags. But I'm afraid that doesn't help me actually answer the question. In particular, although Puppet manifests typically have high data content, they are not fundamentally data objects. Rather, they are expressions of an imperative programming language. It's not clear to me what correspondance you want between the contents of your site.pp and the JSON file you want to produce. – John Bollinger Jul 26 '19 at 12:06
  • I want to migrate from puppet variable to consul kv. I dont know how. May be write script for parse site.pp. – Anton Patsev Jul 26 '19 at 16:41

0 Answers0