如何在puppet清单中的一个类中添加多个源以及如何声明?

时间:2015-03-10 11:50:49

标签: puppet

class practice_oracle
{
$files_inst = [
/tmp/packages/compat-libstdc++-33-3.2.3-47.3.x86_64.rpm,
/tmp/packages/elfutils-libelf-0.125-3.ML5.x86_64.rpm,
/tmp/packages/elfutils-libelf-devel-0.125-3.ML5.x86_64.rpm,
/tmp/packages/gcc-4.6.3-2.fu2012.x86_64.rpm,
/tmp/packages/gcc-c++-4.6.3-2.fu2012.x86_64.rpm,
/tmp/packages/glib2-2.28.8-1.fc15.x86_64.rpm,
]
file {
$files_inst:
ensure => present,
owner => root,
group => root,
mode => 0755,
source => "puppet:///modules/practice_oracle/compat-libstdc++-33-32.3-47.3.x86_64.rpm",
source =>puppet:///modules/practice_oracle/elfutils-libelf-0.125-3.ML5.x86_64.rpm",
source => "puppet:///modules/practice_oracle/elfutils-libelf-devel-0.125-3.ML5.x86_64.rpm",
source => "puppet:///modules/practice_oracle/gcc-4.6.3-2.fu2012.x86_64.rpm",
source => "puppet:///modules/practice_oracle/gcc-c++-4.6.3-2.fu2012.x86_64.rpm",
}

在这段代码中,我尝试编写多个源代码,然后在代理机器上运行,但在代理机器上运行此脚本时,对于列表中的第一个包,所有包的大小都相同。
那么为这个脚本编写什么代码,以及我的代码中的错误是什么。 请帮我解决这个问题。

2 个答案:

答案 0 :(得分:3)

你这样做的方式是行不通的。但是,file类型确实有recurse选项用于目录。您可以按如下方式使用它:

file { '/tmp/packages':
  ensure  => directory,
  source  => 'puppet://modules/practice_oracle",
  owner   => 'root',
  group   => 'root',
  mode    => '0755',
  recurse => true
}

这将填充/tmp/packages目录,其中包含${::modulepath}/practice_oracle/files的整个目录内容。

参考

https://docs.puppetlabs.com/references/latest/type.html#file-attribute-recurse

希望这有帮助

答案 1 :(得分:0)

在你的具体案例中:ptierno说的是什么。

通常,创建一个实用程序定义类型:

define remote_file($dest_dir='/tmp/packages', $module='practice_oracle') {
    file {
        "$dest_dir/$title":
            ensure => present,
            owner => root,
            group => root,
            mode => 0755,
            source => "puppet:///modules/$module/$title",
    }
}

只是

remote_file { $file_inst: }