[chef] Re: convert ruby attributes to json ?


Chronological Thread 
  • From: Matthew Moretti < >
  • To:
  • Subject: [chef] Re: convert ruby attributes to json ?
  • Date: Thu, 10 Oct 2013 04:52:12 -0400

Looks like you might be missing a set of square brackets. I’m not familiar with the cookbook, but the ruby you posted has default['rvm']['user_installs'] set to an array of hashes. So I think you want:

"override_attributes": {
    "rvm": {
       "user_installs": [{
        "user": "www-data",
         "default_ruby": "2.0.0p247",
        "global_gems": [
           {
            "name": "rake"
           },
          {
             "name": "bundler"
          },
           {
            "name": "json"
           },
          {
             "name": "mysql2"
          },
           {
            "name": "libxml-ruby"
           },
          {
             "version": "4.0.20",
            "name": "passenger"
           }
        ]
       }]
    }
   }

Note the square brace on the third and third-from-last line.

Also, if you fire up irb, and require ‘json’ you can just call .to_json on many ruby objects which might help in your conversion.

Matt Moretti



On Thu, Oct 10, 2013 at 4:34 AM, Vladimir Skubriev < " target="_blank"> > wrote:
I need to define a role with knife role edit

And I cannot convert attributes from Readme.md in https://github.com/fnichol/chef-rvm/tree/master

I need to define:

  default['rvm']['user_installs'] = [
  { 'user'            => 'www-data',
    'default_ruby'    => "2.0.0p247",
    'global_gems'     => [
      { 'name'    => 'rake' },
      { 'name'    => 'bundler',},
      { 'name'    => 'json' },
      { 'name'    => 'mysql2' },
      { 'name'    => 'libxml-ruby' },
      { 'name'    => 'passenger', 'version' => "4.0.20" }
    ]
  },
  ]

In json format I create this:

"override_attributes": {
    "rvm": {
      "user_installs": {
        "user": "www-data",
        "default_ruby": "2.0.0p247",
        "global_gems": [
          {
            "name": "rake"
          },
          {
            "name": "bundler"
          },
          {
            "name": "json"
          },
          {
            "name": "mysql2"
          },t
          {
            "name": "libxml-ruby"
          },
          {
            "version": "4.0.20",
            "name": "passenger"
          }
        ]
      }
    }
  },

But I recive an error in chef-client run:

Attribute to_ary is not defined!



/var/chef/cache/cookbooks/chef-rvm/recipes/user_install.rb:

 17:  # limitations under the License.
 18:  #
 19: 
 20:  include_recipe 'rvm'
 21: 
 22:  install_pkg_prereqs
 23: 
 24>> Array(node['rvm']['user_installs']).each do |rvm_user|
 25:    version = rvm_user['version'] || node['rvm']['version']
 26:    branch  = rvm_user['branch'] || node['rvm']['branch']
 27: 
 28:    script_flags      = build_script_flags(branch, version)
 29:    upgrade_strategy  = build_upgrade_strategy(rvm_user['upgrade'])
 30:    installer_url     = rvm_user['installer_url'] || node['rvm']['installer_url']
 31:    rvm_prefix        = rvm_user['home'] ||
 32:                        "#{node['rvm']['user_home_root']}/#{rvm_user['user']}"
 33:    rvm_gem_options   = rvm_user['rvm_gem_options'] || node['rvm']['rvm_gem_options']



How to describe it?

How to describe my vars in json ?



-- 
Best regards,

CVision Lab System Administrator
Vladmir Skubriev




Archive powered by MHonArc 2.6.16.

§