如何像我们对 File[""]、Service[""]、Package[""] 等所做的那样在 puppet 中引用 create_resource
How to Refer create_resource in puppet like we do for File[""], Service[""], Package[""], etc
我有一个带有 exec
资源和 create_resources
函数的人偶文件。我希望 create_resources
在 exec
资源之后立即执行。我该怎么做?
类似于引用 File['name']
,我尝试 Create_Resources[....]
和 notify
,但它不起作用。
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)
对于依赖元参数 require
、before
、subscribe
和 notify
,属性必须是资源类型。指定 notify => Create_Resources[domain_ip_map, $data, $baseconfigdir],
意味着您正试图将 create_resources
函数的输出指定为资源。这不是该参数可接受的类型。
有两种不同的方法可以解决这个问题。您可以添加 notify
或 subscribe
.
对于 subscribe
,您需要添加:
subscribe => Exec['purge-config-files'],
包含 domain_ip_map
资源参数和属性的 $data
散列中的任何必要位置。
使用通知,您需要 assemble 资源标题数组,如下所示(假设使用 stdlib
):
$domain_ip_map_titles = keys($data)
然后将其放入您的 exec
资源中,而不是像这样:
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)
这些都适合您的情况。
我有一个带有 exec
资源和 create_resources
函数的人偶文件。我希望 create_resources
在 exec
资源之后立即执行。我该怎么做?
类似于引用 File['name']
,我尝试 Create_Resources[....]
和 notify
,但它不起作用。
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)
对于依赖元参数 require
、before
、subscribe
和 notify
,属性必须是资源类型。指定 notify => Create_Resources[domain_ip_map, $data, $baseconfigdir],
意味着您正试图将 create_resources
函数的输出指定为资源。这不是该参数可接受的类型。
有两种不同的方法可以解决这个问题。您可以添加 notify
或 subscribe
.
对于 subscribe
,您需要添加:
subscribe => Exec['purge-config-files'],
包含 domain_ip_map
资源参数和属性的 $data
散列中的任何必要位置。
使用通知,您需要 assemble 资源标题数组,如下所示(假设使用 stdlib
):
$domain_ip_map_titles = keys($data)
然后将其放入您的 exec
资源中,而不是像这样:
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)
这些都适合您的情况。