I have written a custom resource sshd_allow_groups
that it's actions change a few of the node's attributes, and those are used in the creation of the template for /etc/sshd_config
in the default recipe (in which the custom resource is hosted). However, since the custom resource is usually called from other cookbooks, there is no way for me to guarantee that the template resource will be called after the changes to the attributes are made, producing a situation in which it takes 2 chef runs to get the desired change.
I'm looking for a way to trigger the template resource after the resource are being called and to be run at the end (in case the resource is called several times). notifies
does not work because the action for the template is not :nothing
, nor it should be, because if for a certain node that resource is not required, the template still needs to be written.
my custom resource:
resource_name :sshd_allow_groups
property :group, String, name_property: true
default_action :append
action :append do
currently = node['tom-ssh']['allow_groups']
if currently
if !currently.include?(group)
node.normal['tom-ssh']['allow_groups'] = currently | [group]
end
else
node.normal['tom-ssh']['allow_groups'] = [group]
end
end
action :remove do
currently = node['tom-ssh']['allow_groups']
if currently && currently.include?(group)
node.normal['tom-ssh']['allow_groups'] = currently - [group]
end
end
another recipe should call it like this:
sshd_allow_groups "bob" do
action :append
end