因资源执行耗时过长引发Puppet依赖循环问题求助
Puppet阶段依赖循环问题排查
配置信息
我的Hiera配置文件os.yaml结构如下:
ordered_staged_classes_which_depend_on_each_other: - epel - redhat classes_which_can_be_performed_arbitrary: - facts - software
阶段顺序已配置为:
Stage[ordered_staged_classes_which_depends_on_each_other] -> Stage[classes_which_can_be_performed_arbitrary]
使用自定义redhat订阅模块,未采用Puppet Forge的rhsm模块。
问题现象
触发如下依赖循环错误:
Error: Found 1 dependency cycle: (Exec[redhat_subscribe] => Class[Redhat] => Stage[ordered_staged_classes_which_depends_on_each_other] => Stage[classes_which_can_be_performed_arbitrary] => Class[facts] => File[Create_facts] => Exec[redhat_subscribe])
注:redhat类与facts类无直接依赖关系,曾推测是Redhat订阅执行耗时过长导致Puppet提前执行其他类,但实际是编译阶段就检测到了依赖闭环。
问题分析
循环链清晰显示:File[Create_facts](属于后置阶段的facts类)与Exec[redhat_subscribe](属于前置阶段的redhat类)形成了双向依赖。虽然两个类没有显式依赖,但大概率是存在以下隐式关联:
File[Create_facts]的父目录由redhat类创建,Puppet自动生成了依赖关系- 文件内容引用了订阅后才存在的系统变量/资源,触发自动依赖
- 自定义redhat模块中
Exec[redhat_subscribe]配置了notify或subscribe,意外关联到了facts类的资源
解决方案
- 打破隐式依赖:检查facts类中
File[Create_facts]的定义,若确认该文件无需依赖redhat订阅操作,可通过require => undef手动切断自动生成的依赖:file { 'Create_facts': # 其他属性配置 require => undef, } - 排查反向关联:查看自定义redhat模块中
Exec[redhat_subscribe]的配置,确保没有notify => File[Create_facts]这类反向依赖声明。 - 验证阶段配置:确认入口文件(如
site.pp)中阶段声明和类的分配是否正确,保证类确实被归属到指定阶段:stage { 'ordered_staged_classes_which_depends_on_each_other': before => Stage[main] } stage { 'classes_which_can_be_performed_arbitrary': require => Stage[ordered_staged_classes_which_depends_on_each_other] } class { 'redhat': stage => 'ordered_staged_classes_which_depends_on_each_other' } class { 'facts': stage => 'classes_which_can_be_performed_arbitrary' }
内容的提问来源于stack exchange,提问作者cd4user
相关产品推荐
相关产品推荐

