如何在傀儡企业3.7中设置条件订阅?

时间:2016-07-07 22:17:20

标签: puppet

我的傀儡企业3.7清单中有一种情况,我可以使用从我的服务到文件的条件'订阅'。我收到此错误消息...

Invalid relationship: Service[openstack-cinder-api] { subscribe => File[/etc/cinder/nfs-shares.conf] }, because File[/etc/cinder/nfs-shares.conf] doesn't seem to be in the catalog

...这里是导致上述错误的木偶代码。请注意,当条件$enabled_backends =~ /netapp-cinder/的计算结果为false时,会发生错误。

class cinder (
... long list of parameters ...
) {
    if ( $enabled_backends =~ /netapp-cinder/ ) {
        file { '/etc/cinder/nfs-shares.conf':
            ensure  => file,
            path    => '/etc/cinder/nfs-shares.conf',
            owner   => cinder,
            group   => cinder,
            mode    => '0640',
            content => template('cinder/nfs-shares.conf.erb'),
        }
    }

    # long list of package and file resources 

    package {'qemu-kvm-rhev':
        ensure        => 'present',
        allow_virtual => false,
    } ->

    package { 'openstack-cinder':
        ensure => 'present',
        name   => 'openstack-cinder',
        before => [
            File['/etc/nova/nova.conf'],
        ],
    } ->

    package { 'python-cinderclient':
        ensure => 'present',
    } ->

    ... even more resource declarations ...

    service { 'openstack-cinder-api':
        ensure    => running,
        enable    => true,
        subscribe => [
            File['/etc/cinder/cinder.conf'],
            File['/etc/cinder/nfs-shares.conf'],
        ],
    } ->

    service { 'openstack-cinder-scheduler':
        ensure    => running,
        enable    => true,
        subscribe => [
            File['/etc/cinder/cinder.conf'],
            File['/etc/cinder/nfs-shares.conf'],
        ],
    } ->

    service { 'openstack-cinder-volume':
        ensure    => running,
        enable    => true,
        subscribe => [
            File['/etc/cinder/cinder.conf'],
            File['/etc/cinder/nfs-shares.conf'],
        ],
    }

    service { 'openstack-cinder-backup':
        ensure    => running,
        enable    => true,
        subscribe => [
            File['/etc/cinder/cinder.conf'],
            File['/etc/cinder/nfs-shares.conf'],
        ],
    } -> 

    ... more puppet code ...

有什么办法可以让订阅文件['/ etc / cinder / nfs-shares.conf']有条件吗?

1 个答案:

答案 0 :(得分:1)

file { '/etc/cinder/nfs-shares.conf':
  ensure  => file,
  path    => '/etc/cinder/nfs-shares.conf',
  owner   => cinder,
  group   => cinder,
  mode    => '0640',
  content => template('cinder/nfs-shares.conf.erb'),
  notify  => Service['openstack-cinder-api', 'openstack-cinder-scheduler', 'openstack-cinder-volume', 'openstack-cinder-backup'],  <-- add this attribute
}

然后从openstack服务中删除File['/etc/cinder/nfs-shares.conf']上的所有订阅。现在,服务重启触发器位于条件内,您将获得所需的行为。

如果您使用未来的解析器并从3.7升级,我还建议将这些openstack服务资源转换为lambda,因为它是针对puppetlabs支持的EOL。