How do I use a chef recipe that's defined in terms of roles if I'm not using roles?

StackOverflow https://stackoverflow.com/questions/23254479

  •  08-07-2023
  •  | 
  •  

Question

I'm trying to use the Opscode ntp cookbook but the instructions on using it don't make any sense to me. It says:

Set up the ntp attributes in a role. For example in a base.rb role applied to all nodes:

name 'base'
description 'Role applied to all systems'
default_attributes(
  'ntp' => {
    'servers' => ['time0.int.example.org', 'time1.int.example.org']
  }
)

Then in an ntpserver.rb role that is applied to NTP servers (e.g., time.int.example.org):

name 'ntp_server'
description 'Role applied to the system that should be an NTP server.'
default_attributes(
  'ntp' => {
    'is_server'    => 'true',
    'servers'      => ['0.pool.ntp.org', '1.pool.ntp.org'],
    'peers'        => ['time0.int.example.org', 'time1.int.example.org'],
    'restrictions' => ['10.0.0.0 mask 255.0.0.0 nomodify notrap']
  }
)

The timeX.int.example.org used in these roles should be the names or IP addresses of internal NTP servers. Then simply add ntp, or ntp::default to your run_list to apply the ntp daemon's configuration.

We're not using roles in our configuration. We're writing recipes which include other recipes, and then running the appropriate recipe on the host we're trying to provision.

How can I use the cookbook without using roles?

Was it helpful?

Solution

You can develop a wrapper cookbook which sets the node attributes and then includes the recipe. An example recipe of such a wrapper cookbook could look like this:

# Set the node attributes for ntp
node.default['ntp']['servers'] = ['time0.int.example.org', 'time1.int.example.org']

# include the recipe
include_recipe 'ntp'
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top