【问题标题】:Puppet issue with apt::source and stagesapt::source 和阶段的木偶问题
【发布时间】:2013-03-13 12:00:27
【问题描述】:

我已经完成了本地 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)                             

我还想申请以下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
    }
}

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

# 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

问题似乎出在stage => 'setup' 参数上,但我想了解发生了什么以及我能做些什么来解决这个问题(我继承了一个大型 puppet 代码库 - 以上只是一个证明概念 - 它使用 stage 东西,我还不想删除它,因为我不太了解 Puppet 的内部工作原理)。

更新 #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}
}

但是,这并不能解决问题,只会产生另一个依赖循环。

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

完整的调试输出here。依赖图为

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

【问题讨论】:

    标签: deployment puppet


    【解决方案1】:

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

    但随后 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:: 之前发生)更新隐含的设置阶段资源!)

    我希望这会有所帮助,它可能看起来很复杂 - 尤其是锚点。

    【讨论】:

    • 你说的很有道理,因此我也尝试将apt::source 移动到setup 阶段,但这也不是很好(请参阅我所做的编辑)
    • 但没有实际的修复建议?
    猜你喜欢
    • 1970-01-01
    • 2014-09-10
    • 1970-01-01
    • 2013-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多