13

I know the basics of ordering in puppet to run apt-get update before a specific package but would like to specify to just run apt-get update only once and then execute the rest of the puppet file. Is that possible?

All of the ways listed Here need to either run apt-get before every package or use arrows or requires to specify each package.

4

2 回答 2

28

这将是我从该列表中的建议:

exec { "apt-update":
    command => "/usr/bin/apt-get update"
}

Exec["apt-update"] -> Package <| |>

这将确保 exec 在任何包之前运行,而不是 exec 在每个包之前运行。事实上,puppet 中的任何资源每次 puppet run 最多只能执行一次

但是,如果您希望 exec 在任何类型的资源之前发生,我想您可以执行以下操作:

exec { "apt-update":
    command => "/usr/bin/apt-get update",
    before  => Stage["main"],
}

“主”阶段是每个资源的默认阶段,因此这将使 exec 在其他任何事情之前发生。

我希望这个对你有用。

于 2013-07-17T01:42:50.880 回答
3

使用puppetlabs-apt模块,为将要安装的任何包定义对模块的依赖项就足够了:

Class['apt::update'] -> Package <| provider == 'apt' |>

这假设 的基本配置apt,例如:

class { 'apt':
    update => {
      frequency => 'daily',
    },
    purge => {
      'sources.list' => false,
      'sources.list.d' => true,
    },
  }
于 2016-05-13T07:08:15.023 回答