Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8949439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:13:02+00:00 2026-06-15T13:13:02+00:00

I am using chef version 10.16.2 I have a role (in ruby format). I

  • 0

I am using chef version 10.16.2
I have a role (in ruby format). I need to access an attrubute set in one of the cookbooks

eg.

name "basebox"
description "A basic box with some packages, ruby and rbenv installed"

deployers = node['users']['names'].find {|k,v| v['role'] == "deploy" }

override_attributes {
  {"rbenv" => {
      "group_users" => deployers
    }
  }
}

run_list [ 
          "recipe[users]",
          "recipe[packages]",
          "recipe[nginx]",
          "recipe[ruby]"
         ]

I am using chef-solo so i cannot use search as given on http://wiki.opscode.com/display/chef/Search#Search-FindNodeswithaRoleintheExpandedRunList

How do i access node attributes in a role definition ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:13:03+00:00Added an answer on June 15, 2026 at 1:13 pm

    Roles are JSON data.

    That is, when you upload the role Ruby file to the server with knife, they are converted to JSON. Consider this role:

    name "gaming-system"
    description "Systems used for gaming"
    run_list(
      "recipe[steam::installer]",
      "recipe[teamspeak3::client]"
    )
    

    When I upload it with knife role from file gaming-system.rb, I have this on the server:

    {
      "name": "gaming-system",
      "description": "Systems used for gaming",
      "json_class": "Chef::Role",
      "default_attributes": {
      },
      "override_attributes": {
      },
      "chef_type": "role",
      "run_list": [
        "recipe[steam::installer]",
        "recipe[teamspeak3::client]"
      ],
      "env_run_lists": {
      }
    }
    

    The reason for the Ruby DSL is that it is “nicer” or “easier” to write than the JSON. Compare the lines and syntax, and it’s easy to see which is preferable to new users (who may not be familiar with JSON).

    That data is consumed through the API. If you need to do any logic with attributes on your node, do it in a recipe.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using Chef to manage our servers. My roles/app.rb looks like this:
I've just started using chef-solo. I've started using chef-solo to build my Ruby on
I'm using chef-solo to test my cookbooks locally, but I want to be able
I'm using Vagrant + Chef Solo to set up a CakePHP app. I'd like
I'm writing server automation script using Chef, and I need to check the installed
Using online interfaces to a version control system is a nice way to have
I am trying to test my chef cookbooks in VM using chef-minitest-handler and Vagrant.
How can you use a Chef recipe to set an environment variable? I need
I've got a vm running using vagrant, and I'm provisioning it with Chef. One
I am using chef to automate the install of graphite on ubuntu. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.