Search code examples
puppet

How to fix my puppet dependency in the correct way?


I have a module apt (my custom module, I am learning and want to explore more) for apt-get update. I also have two user defined resource type apt::key and apt::source.

Let say I want to install a package example docker for which we need to add an apt key and source. Hence I ideally want execution to happen in order

  1. configure key then source for apt
  2. apt-get update
  3. install docker package

Now I want to ensure I am also having my code sitting under correct classes and following correct dependencies. My directory structure looks like

├── apt
│   └── manifests
│       ├── init.pp
│       ├── key.pp
│       ├── packages.pp
│       ├── source.pp
│       └── update.pp
└── docker
    └── manifests
        ├── init.pp
        ├── install.pp

where should my definition of key and source for docker and how should I achieve the dependency? Should my dependency be inside these modules or in default manifest file under node definition?

EDIT: Adding little more context I am confused as I can achieve this by with two alternatives:

  • having docker::install have apt::source and apt::key for docker. In this scenario my apt::source will notify apt::update and docker package will be installed after the apt-update. Though the problem with this approach is I have to run apt update after each apt source change.
  • having apt::sources which declare all sources and keys required for my project. The problem with this is my apt module would coupled with the other modules.

Hence I want to see how people achieve this and are there other alternatives which I haven't thought.


Solution

  • having docker::install have apt::source and apt::key for docker

    I think this is the correct approach, as it contains/encapsulates all of the resources neatly into the module (docker) that requires them.

    Though the problem with this approach is I have to run apt update after each apt source change.

    This is something the system should be doing - if the source changes, e.g. a URL change, you ought to be running apt-get update to reload the package lists as they may be out of date. It seems unlikely to me that the source would change often.

    If you have multiple apt sources across the catalog (i.e. from other modules) then the Puppet agent will still only refresh the Exec[apt_update] once, after it's evaluated all of the apt source resources (notifying something puts an implicit before relationship in too.)