[chef] Recipe attributes for previous resources


Chronological Thread 
  • From: Yoshi Spendiff < >
  • To: chef < >
  • Subject: [chef] Recipe attributes for previous resources
  • Date: Mon, 15 Jun 2015 14:27:49 -0700

Hi,

I'm using the sshd cookbook to configure the ssh server on hosts. I include this recipe with a set of attributes in an attribute file to configure my sshd config file. One of which is this:

default['sshd']['sshd_config']['PasswordAuthentication'] = 'no'

I then have the following in one of the recipes in my base cookbook which gets applied to all nodes:

include_recipe 'sshd'

I have another recipe that creates a user on a machine and configures it. Only for machines where this user exists I want to enable password authentication for SSH, so this user works for the purpose it's designed for. In the recipe I set the following:

node.set['sshd']['sshd_config']['PasswordAuthentication'] = 'yes'
include_recipe 'sshd'


Everything works well if I run the user create recipe before the base recipe as the attribute gets changed before the sshd recipe is run. If I run the user creation recipe after the base then password authentication is disabled as the sshd recipe has already been included and run before the attribute change.

My question is what is the best way to handle this situation? Is there some way to notify the template of an attribute change in the recipe or do I have to redefine the sshd config template resource?
Otherwise do I just have to deal with having a recipe where the order in the run list is important within a cookbook (and not be able to handle this with include_recipe for a dependency, as the user recipe isn't run on every node).


  • [chef] Recipe attributes for previous resources, Yoshi Spendiff, 06/15/2015

Archive powered by MHonArc 2.6.16.

§