Kenshin
Kenshin

Reputation: 1030

How to Refer create_resource in puppet like we do for File[""], Service[""], Package[""], etc

I have a puppet file with an exec resource and create_resources function. I want create_resources to be executed right after the exec resource. How do I do this?

Similar to referencing File['name'], I tried Create_Resources[....] with notify, but it is not working.

notify => Create_Resources[domain_ip_map, $data, $baseconfigdir].

init.pp

exec { 'purge-config-files':
  before  => [File["${config_file_service}"], File["${config_file_host}"]],
  command => "/bin/rm -f ${baseconfigdir}/*",
  #notify => Create_Resources[domain_ip_map, $data, $baseconfigdir],
}

create_resources(domain_ip_map, $data)

Upvotes: 2

Views: 1243

Answers (1)

Matthew Schuchard
Matthew Schuchard

Reputation: 28774

For the dependency metaparameters require, before, subscribe, and notify, the attributes must be resource types. Specifying notify => Create_Resources[domain_ip_map, $data, $baseconfigdir], means you are attempting to specify the output of the create_resources function as the resources. That is not going to be an acceptable type for that parameter.

There are two different ways to go about this. You can either add a notify or a subscribe.

With the subscribe, you would need to add:

subscribe => Exec['purge-config-files'],

everywhere necessary into the $data hash that contains your domain_ip_map resources' parameters and attributes.

With the notify, you would need to assemble the array of resource titles like the following (assuming using stdlib):

$domain_ip_map_titles = keys($data)

and then put that in your exec resource instead like this:

exec { 'purge-config-files':
  before  => [File["${config_file_service}"], File["${config_file_host}"]],
  command => "/bin/rm -f ${baseconfigdir}/*",
  notify  => Domain_ip_map[$domain_ip_map_titles],
}

create_resources(domain_ip_map, $data)

Either of those will work for your situation.

Upvotes: 2

Related Questions