Ask Your Question

Dependency cycles with apt module

asked 2014-07-16 13:47:44 -0600

n0thing gravatar image

updated 2014-07-16 17:04:49 -0600

ramindk gravatar image

I'm trying to write a manifest that performs a bunch of package installs, and then installs and starts an instance of postgres. However, before I install any packages, I must make sure the apt-get repositories are up to date. I've reduced my issue to the following:

stage { 'first': 
    before => Stage['main']

class { '::apt':
    always_apt_update => true,
    stage => first

class { 'postgresql::globals':
    manage_package_repo => true
class { 'postgresql::server': }

I have also tried replacing the ::apt class declaration with:

class { 'apt::update':
    stage => first

Both produce dependency cycles, presumably because the Postgres module internally uses apt::update:

==> default: (Anchor[apt_key ACCC4CF8 present] => Apt::Key[Add key: ACCC4CF8 from Apt::Source] => File[] => Exec[apt_update] => Class[Apt::Update] => Stage[init] => Stage[main] => Class[Postgresql::Repo::Apt_postgresql_org] => Apt::Source[] => File[])

What would be the most idiomatic way of solving such dependency issues, considering I need to install Postgres with manage_package_repo == true and need to perform an apt-get update first of all (and would much rather not declare an exec)?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2014-07-17 11:42:07 -0600

ramindk gravatar image

updated 2014-07-17 11:43:00 -0600

This code can be problematic for two reasons. It'll realize any virtual Package resources and it makes it impossible to manage packages in the apt module.

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

Neither of those are hard to work around, but the resulting manifests will be on the hacky side.

If you want to keep using stages, I like them for apt/yum myself, you will need to do everything involving ::apt in the same stage. You'll need to convert the parts of your code to reflect that. Probably looks something like this.

apt::source { 'postgres':
   stage => first,

The other part is that nothing in your postgres module or any module in stage => main, can depend upon anything in another stage. Based on your error you'll need to remove any require within Class[Postgresql::Repo::Apt_postgresql_org]

edit flag offensive delete link more


Thank you, class { '::apt': always_apt_update => true}-> Package <||> solved the problem for me!

n0thing gravatar imagen0thing ( 2014-07-17 15:21:39 -0600 )edit

answered 2014-07-16 18:58:01 -0600

spuder gravatar image

The apt puppet labs module is smart enough to call apt-get update in most circumstances. You can see this by looking at the source when apt::update class is called.

Looking at your code, there doesn't appear to be any reason for using the apt module (you aren't adding any ppa's, keys, back ports, pinning) so really the apt module does you no good here.

While probably not what you wanted to hear, you'll either need to use one of the classes in the apt module that calls apt::update (such as adding a ppa), or you will need to use an exec.

exec { "apt-update":
    command => "/usr/bin/apt-get update"
Exec["apt-update"] -> Package <| |>

edit flag offensive delete link more


Thanks! My minimized example doesn't show why it's needed, but if it's relevant: it's because I'm running: class { 'apt::update': }->class { 'install_a_bunch_of_packages': }->class { 'install_postgres': }, and install_a_bunch_of_packages will simply fail if apt::update doesn't run explicitly first.

n0thing gravatar imagen0thing ( 2014-07-16 19:21:05 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-07-16 13:47:44 -0600

Seen: 3,389 times

Last updated: Jul 17 '14