如何引用当前人偶模块的文件目录?
How can I refer to the current puppet module's files directory?
这很可能是反模式,但我还是想知道:
我需要提取 puppet 中的 tgz,然后将内容移动到其他地方。是否可以在 puppet exec { }
中引用它存储在磁盘上的文件?
例如/usr/local/puppet
有puppet,/usr/local/puppet/modules/components/files/file.tgz
有我需要的tgz文件。在 exec { }
中我可以做类似 command => "/bin/cp $modules/components/files/file.tgz /somewhere_else"
的事情吗?还是我必须先声明一个 file { source => "..." }
区块?
如果您 运行 用 puppet apply
玩偶,这两种方法都是正确的。
在主代理架构中使用 exec
复制文件可能根本不起作用。
在我看来,使用 file
资源更 "puppet-like" 但有一个明显的缺点。
您可以使用:
file { '/some_path/somewhere_else':
source => '/usr/local/puppet/modules/components/files/file.tgz',
}
这将创建与 /usr/local/puppet/modules/components/files/file.tgz
内容相同的文件 /some_path/somewhere_else
(它将创建原始文件的副本)。
但是如果 /some_path
在文件系统中不存在,命令将失败。
如果您正在使用 tgz
文件,您还可以考虑使用一些 archive puppet modules e.g gini.
更新:
我可以提出两种方法:
对旧的人偶版本使用 puppet file server to serve files (or define module path)。接下来只需使用它,例如:
file { '/some_path/somewhere_else':
source => "puppet:///modules/components/file.tgz',
}
定义自定义事实 1, 2 指向包含所需文件的文件系统中的路径。例如:
file { '/some_path/somewhere_else':
source => "${::my_custom_fact}/some_path/file.tgz',
}
我认为 core facts 中的任何一个都可能对您有用。
这很可能是反模式,但我还是想知道:
我需要提取 puppet 中的 tgz,然后将内容移动到其他地方。是否可以在 puppet exec { }
中引用它存储在磁盘上的文件?
例如/usr/local/puppet
有puppet,/usr/local/puppet/modules/components/files/file.tgz
有我需要的tgz文件。在 exec { }
中我可以做类似 command => "/bin/cp $modules/components/files/file.tgz /somewhere_else"
的事情吗?还是我必须先声明一个 file { source => "..." }
区块?
如果您 运行 用 puppet apply
玩偶,这两种方法都是正确的。
在主代理架构中使用 exec
复制文件可能根本不起作用。
在我看来,使用 file
资源更 "puppet-like" 但有一个明显的缺点。
您可以使用:
file { '/some_path/somewhere_else':
source => '/usr/local/puppet/modules/components/files/file.tgz',
}
这将创建与 /usr/local/puppet/modules/components/files/file.tgz
内容相同的文件 /some_path/somewhere_else
(它将创建原始文件的副本)。
但是如果 /some_path
在文件系统中不存在,命令将失败。
如果您正在使用 tgz
文件,您还可以考虑使用一些 archive puppet modules e.g gini.
更新: 我可以提出两种方法:
对旧的人偶版本使用 puppet file server to serve files (or define module path)。接下来只需使用它,例如:
file { '/some_path/somewhere_else': source => "puppet:///modules/components/file.tgz', }
定义自定义事实 1, 2 指向包含所需文件的文件系统中的路径。例如:
file { '/some_path/somewhere_else': source => "${::my_custom_fact}/some_path/file.tgz', }
我认为 core facts 中的任何一个都可能对您有用。