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 9129153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:40:51+00:00 2026-06-17T07:40:51+00:00

I would like the Chef cookbook network_interfaces to have dynamic values for ip addresses,

  • 0

I would like the Chef cookbook network_interfaces to have dynamic values for ip addresses, netmasks and alike for each of my nodes. What works for me is the following:

db_role.rb (block1):

override_attributes(
  "network_interfaces" => {
      :device => 'eth0',
      :address => '123.123.123.123',
  }
)

But that is not very dynamic. My idea was to submit the ip address(, netmask, etc.) to each node on knife bootstrap.

The node would then look like so (block2):

{
    "normal": {
      "network_interfaces" => {
          "device" : "eth0",
          "address" : "123.123.123.123"
      }
    },
    "name": "foobar",
    "run_list": [
       "recipe[zsh]",
       "role[networking_interfaces]"
    ]
}

Unfortunately the network_interfaces cookbook does not pick up those values by default. My idea was to reference the node specific attributes shown in block2 in the roles definition like so:

override_attributes(
  "network_interfaces" => {
      :device => node['network_interfaces']['device'],
      :address => node['network_interfaces']['address'],
  }
)

This does not work because it is not json obviously and Chef can not handle dynamically allocated values in roles files.

How can I achieve to run the network_interfaces recipe and pass my node specific values to it?

  • 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-17T07:40:52+00:00Added an answer on June 17, 2026 at 7:40 am

    If you add normal attributes via knife bootstrap -j …, and leave override attributes in the role, the override will take over (see http://docs.opscode.com/essentials_node_object_attributes_precedence.html for a complete list of attribute precedence). If you have deleted override_attributes from db_role.rb before running knife bootstrap, or changed it to default_attributes, then setting IP in node attributes should have worked.

    The last snippet won’t work: roles are static JSON documents on the Chef server, and Ruby is only interpreted once by knife when uploading role to the server (http://docs.opscode.com/essentials_roles_formats.html). You can’t refer to node’s attributes from role’s Ruby code, as it’s compiled to JSON before it even touches any node. If you want to try a similar approach, you need to use a custom cookbook (say, my_network_interfaces) with a recipe that would look somewhat like this:

    node.set['network_interface']['device'] = …
    node.set['network_interface']['address'] = …
    include_recipe 'network_interfaces'
    

    This way, you’d use network_interfaces as a “library” cookbook, called by your “application” cookbook my_network_interfaces which implements whatever logic you need. From your question, I can’t suggest how would you compute device and address, as your example just tries to copy same attributes, which is a no-op. As far as I understand what you want to achieve, you want to have default_attributes in the role, and pass specific JSON with normal attributes to knife bootstrap to override the defaults.

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

Sidebar

Related Questions

In Chef I have an array that I would like to print out comma
Would like to parse IPv4 address from exit-addresses . Format of the file: ExitNode
Would like to sort the following data the way allows in the order of
Would like to ask how to add an if statement into the following code.
I have been using Chef to manage our servers. My roles/app.rb looks like this:
would like to know how can this be implemented in Joomla. I have a
Would like to sort the following XML by joining the fsxml/formula/ingrrow where itemcode =
I have an environment ( Graphite ) that looks like the following: N worker
I'm using Chef with Vagrant and would like to build a rails stack with
Would like to have an executable save its state by modifying its own global

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.