apt :: source和stage的puppet问题

Unk*_*own 8 deployment puppet

我有一个本地Puppet安装,我已经完成了:

# puppet module install puppetlabs/apt  
Preparing to install into /etc/puppet/modules ...            
Downloading from http://forge.puppetlabs.com ...             
Installing -- do not interrupt ...                           
/etc/puppet/modules                                          
??? puppetlabs-apt (v1.1.0)                                  
  ??? puppetlabs-stdlib (v3.2.0)                             
Run Code Online (Sandbox Code Playgroud)

我还有以下nodes.pp要申请的内容:

node default {                                                              
    include stdlib                                                      

    class {'apt':
            always_apt_update => true,
            disable_keys => true,
            stage => 'setup'
    }
    ->
    apt::source { "cassandra":
            location => "http://debian.datastax.com/community",
            release => "stable",
            repos => "main",
            key => "B999A372",
            key_source => "http://debian.datastax.com/debian/repo_key", 
            include_src => false
    }
}
Run Code Online (Sandbox Code Playgroud)

当我尝试应用它时,我得到:

# puppet apply nodes.pp
err: Could not apply complete catalog: Found 1 dependency cycle:
(Anchor[apt::key B999A372 present] => Apt::Key[Add key: B999A372 from Apt::Source cassandra] => File[cassandra.list] => Exec[apt_update] => Class[Apt::Update] => Stage[setup] => Stage[main] => Class[Main] => Node[default] => Apt::Source[cassandra] => File[cassandra.list])
Try the '--graph' option and opening the resulting '.dot' file in OmniGraffle or GraphViz
notice: Finished catalog run in 0.12 seconds
Run Code Online (Sandbox Code Playgroud)

问题似乎在于stage => 'setup'参数,但我想了解发生了什么,我该怎么做才能解决这个问题(我继承了一个大型的木偶代码库 - 上面只是一个概念证明 - 它使用了stage事情,我不想删除它,因为我没有得到Puppet的内部工作非常好atm).

更新#1

尝试将apt::source步骤移动到setup舞台上,如下所示:

class cassandra {
     apt::source { "cassandra":                                               
        location => "http://debian.datastax.com/community",              
        release => "stable",                                             
        repos => "main",                                                 
        key => "B999A372",                                               
        key_source => "http://debian.datastax.com/debian/repo_key",      
        include_src => false                                             
    }                                                                        
}                                                                           

node default {                                                               
    include stdlib                                                           

    class {'apt':                                                            
        always_apt_update => true,                                       
        disable_keys => true,
        stage => setup
    }                                                                        
    ->                                                                       
    class {'cassandra': stage => setup}
}
Run Code Online (Sandbox Code Playgroud)

但是,这并没有解决问题,只是生成另一个依赖循环.

err: Could not apply complete catalog: Found 1 dependency cycle:
(Anchor[apt::key B999A372 present] => Apt::Key[Add key: B999A372 from Apt::Source cassandra] => File[cassandra.list] => Exec[apt_update] => Class[Apt::Update] => Anchor[apt::update] => Class[Apt] => Class[Cassandra] => Apt::Source[cassandra] => File[cassandra.list])
Run Code Online (Sandbox Code Playgroud)

这里完全调试输出.依赖图是这个

所以在我看来,尝试以"自然"方式(通过->运算符)强制执行操作顺序会导致这种奇怪的依赖循环.

Sek*_*ekm 3

基本上看起来你的 apt::source 指定了一个密钥。apt::key 的 apt::source 声明指出,在添加文件 cassandra.list 之前需要处理 apt::key。这有道理吧?

但是 cassandra 文件资源有一个 Exec['apt_update'] 的通知,它存在于 apt::update 中。它是一个仅刷新包,仅由正在执行并通知它的 cassandra 文件资源触发。

Exec['apt_update'] 位于 apt::update 内部,因此需要对 Class['apt::update'] 进行处理才能被视为已处理。

现在实际的问题发生在 apt 声明中。您已使用元参数 stage => 'setup' 声明了 apt(apt 模块的初始化清单)。您会发现 apt 实际上包含 apt::update,这很好 - 但它还定义了一个锚点“apt::update”,它需要类 apt::update。由于 apt 对 apt::update 的依赖,我们现在在安装阶段也隐式依赖于 apt::update 。

主阶段取决于设置阶段,任何未指定阶段的内容都会自动选择主阶段 - 因此 File['cassandra.list'] 也是主阶段资源(但需要在 apt::update 之前发生)隐式设置阶段资源!)

我希望这会有所帮助,它可能看起来相当复杂 - 特别是对于锚点。