Dependency cycles with apt module

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:

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

2 Answers

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]