yum – 我怎么能告诉Puppet“如果我宣布X类,在Y级之前应用它的资源”?

在我的Puppet配置中,我想说“如果我声明类X,请在类Y之前应用它的资源.”换句话说,我想声明一个排序,但对是否应用X类保持沉.

如果我正确理解“之前”元参数,说:

class X {
    ...
    before => Class['Y'],}

class Y {
    ...
}

node N {
    include Y
}

node M {
    include X
    include Y
}

将在节点M和N上包括X和Y的资源.相反,我想要的是分别表达,“仅应用Y”或“应用X和Y,并在Y之前应用X”.

对于上下文,我想要更具体地做的是确保在Puppet应用包资源之前配置我的Yum存储库.我想从一些节点中省略一些存储库.我希望我的包资源定义对相应的存储库保持天真;我不想丢弃我的包资源定义与依赖于特定存储库.

我尝试使用Run Stages,但超出最简单的配置,它们似乎会导致依赖循环.例如,这将工作:

stage { 'first': before => Stage['main'] }

class X {
    ...
    before => Class['Y'],}

class Y {
    ...
}

node N {
    include Y
}

node M {
    class { "X": stage => first }
    include Y
}

但这不会:

stage { 'first': before => Stage['main'] }

class X {
    ...
    class { "Z": stage => first } # to avoid Z "floating off"
    before => Class['Y'],}

class Y {
    ...
    include Z
}

class Z { ... }

node N {
    include Y
}

node M {
    class { "X": stage => first }
    include Y
}

在后者中,Puppet认为存在依赖循环.我认为这是由于Z被宣布并且其资源在两个不同阶段进行管理.我可以在“第一”阶段简化我需要的类,以避免我在实践中看到的依赖循环问题,但Puppet文档传播FUD关于Run Stages.

这是配置的特定位置,使Run Stages对我来说真的没什么吸引力.在开发虚拟机中,我通过“devrepo”在本地引导Yum服务器.

class yum::devrepo {

    # Ensures httpd is running as a Yum server before anything else
    # tries to install packages from it.
    exec { 'httpd-for-yum':
        command => '/sbin/service httpd restart',require => Class['yum::server'],}

    yumrepo {
        "devrepo":
            require    => [Exec['httpd-for-yum'],],descr      => "Local Dev YUM Repo",baseurl    => "http://localhost/repos/redhat/5/x86_64/",gpgcheck   => "0",enabled    => "1",}
}

class yum::server {

    include httpd

    package { ['createrepo']:
        ensure => present;
    }

    exec { 'update-repo-Metadata':
        require => [ Package['createrepo']],cwd => '/var/www/html/yum',command => '/usr/bin/createrepo --update -d repos/redhat/5/x86_64/',creates => '/var/www/html/yum/repos/redhat/5/x86_64/repodata/repomd.xml',}

    file {'/etc/httpd/conf.d/yum.conf':
        ensure  => file,mode    => 0644,source  => "puppet:///modules/yum/yum_httpd.conf",require => Package['httpd'],notify  => Service['httpd'],}
}

我想在一些节点上包含我的生产Yum repo,在其他节点上包含dev repo.

如果我将yum :: server和yum :: devrepo放在“first”阶段,那么稍后其他类中的httpd声明会导致问题,因为其他类将httpd放在主阶段.

如果Puppet可以表达“如果我声明类X,在Y类之前应用它的资源”,怎么样?如果没有,如何在没有依赖循环的情况下获得我想要的顺序,而不包括我想要省略的Yum存储库资源?

不确定它是否可行,但也许您可以尝试在节点级范围上定义依赖项.例如:
class X {
    ...
}

class Y {
    ...
}

node N {
   include Y
}

node M {
    Class['X'] -> Class['Y']
    include X
    include Y
}

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...