简体   繁体   中英

Puppet dependency resolution ordering

I have a couple hosts which have Docker containers on them, so I've defined a class called apps::docker which installs Docker on the hosts:

class apps::docker {
  include apps::docker::repository, apps::docker::install,
    apps::docker::service

  Class["Apps::Docker::Repository"] ->
  Class["Apps::Docker::Install"] ->
  Class["Apps::Docker::Service"]

  Package["Docker"] ~> Service["Docker"]
}

class apps::docker::repository {
  apt::source { 'docker':
    location    => "http://get.docker.io/ubuntu",
    key         => "A88D21E9",
    release     => "docker",
    repos       => "main",
    include_src => false
  }
}

class apps::docker::install {
  package { 'docker':
    name   => "lxc-docker",
    ensure => present
}

class apps::docker::service {
  service { 'docker':
    provider   => 'upstart',
    enable     => true,
    ensure     => running,
    hasrestart => true,
    hasstatus  => true
  }
}

Pretty simple stuff, actually.

The problem is that when I try to define a class which depends on this class, the execution happens out of order and commands fail. For example, my class profiles::shiningstar::containers depends on apps::docker as defined in profiles::shiningstar :

class profiles::shiningstar {
  include apps::docker
  include profiles::shiningstar::containers

  Class["Apps::Docker"] -> Class["Profiles::Shiningstar::Containers"]
}

Unfortunately, this doesn't work as seen below:

Error: /Stage[main]/Profiles::Shiningstar::Containers::Puppetmaster::Pull/Docker::Image[rfkrocktk/puppetmaster:1.0.5]/Exec[docker pull rfkrocktk/puppetmaster:1.0.5]: Could not evaluate: Could not find command 'docker'
... (similar errors)
Notice: /Stage[main]/Apps::Docker::Repository/Apt::Source[docker]/Apt::Key[Add key: A88D21E9 from Apt::Source docker]/Apt_key[Add key: A88D21E9 from Apt::Source docker]/ensure: created

It's executing things completely out of order. What's wrong with my configuration and how can I specify that ALL of the dependencies of apps::docker must be satisfied before profiles::shiningstar::containers ?

You probably want to contain the inner classes instead of just including them.

class apps::docker {
    contain apps::docker::repository
    contain apps::docker::install
    contain apps::docker::service

    Class['apps::docker::repository']
    ->
    Class['apps::docker::install']
    ~>
    Class['apps::docker::service']
}

Note that it makes sense (in your case at least) to make the ::install class as a whole notify all of the ::service class. The makes you more flexible in refactoring the respective implementation of those classes.

Edited after first comment - don't try to put chaining arrows between contain statements.

You should use an anchor, that will ensure that all dependencies are built

class apps::docker {
  include apps::docker::repository, apps::docker::install,
    apps::docker::service

  Class["Apps::Docker::Repository"] ->
  Class["Apps::Docker::Install"] ->
  Class["Apps::Docker::Service"] ->
  anchor{"apps::docker":}

  Package["Docker"] ~> Service["Docker"]
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM