Ask Your Question
2

Dependency cycles with apt module

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

n0thing gravatar image

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

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 apt.postgresql.org] => File[apt.postgresql.org.list] => Exec[apt_update] => Class[Apt::Update] => Stage[init] => Stage[main] => Class[Postgresql::Repo::Apt_postgresql_org] => Apt::Source[apt.postgresql.org] => File[apt.postgresql.org.list])

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
2

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

ramindk gravatar image

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

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

Comments

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

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

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

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 <| |>

https://mig5.net/content/enforcing-apt-get-update-prior-any-packages-installing-puppet http://stackoverflow.com/questions/17689180/puppet-apt-get-update-only-once-before-anything-else http://stackoverflow.com/questions/10845864/puppet-trick-run-apt-get-update-before-installing-other-packages

edit flag offensive delete link more

Comments

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 -0500 )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

Stats

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

Seen: 2,791 times

Last updated: Jul 17 '14