简体   繁体   English

如何影响另一个人偶模块中声明的资源类型

[英]How Affect Resource Type Declared In Another Puppet Module

I include the class nova::compute::libvirt and this class defines a Package resource like so: 我包含了nova::compute::libvirt类,该类定义了Package资源,如下所示:

package { 'libvirt-nwfilter':
  ensure => present,
  name   => $::nova::params::libvirt_nwfilter_package_name,
  before => Service['libvirt'],
  tag    => ['openstack', 'nova-support-package'],
}

The problem is that the RPM is in a YUM repo that is not enabled enabled=0 . 问题在于RPM在未启用的YUM存储库中,其中enabled=0 I could solve this issue by changing nova::conpute::libvirt so that Package resource looked like this: 我可以通过更改nova::conpute::libvirt来解决此问题,以便Package资源如下所示:

package { 'libvirt-nwfilter':
  ensure => present,
  name   => $::nova::params::libvirt_nwfilter_package_name,
  before => Service['libvirt'],
  tag    => ['openstack', 'nova-support-package'],
  install_options => ['--enablerepo', 'redhat_updates'],
}

But I'd like to not have to modified a module I got from puppet forge because the next time someone else setups up a puppet master they might forget to make the modification. 但是我不想修改从puppet forge获得的模块,因为下次其他人设置一个puppet master时,他们可能会忘记进行修改。 Is there something I can do from the class that includes nova::compute::libvirt ? 我可以从包括nova::compute::libvirt的类中做些什么?

You can solve this problem by enabling the redhat_updates yum repo with a yumrepo resource, and then specifying a metaparameter for it to be applied before the class. 您可以通过使用yumrepo资源启用redhat_updates yum repo,然后指定要在类之前应用的元参数来解决此问题。

yumrepo { "redhat_updates":
  baseurl  => "baseurl",
  descr    => "Redhat Updates",
  enabled  => 1,
  gpgcheck => 0,
  before   => Class['nova::compute::libvirt'],
}

https://docs.puppet.com/puppet/latest/types/yumrepo.html https://docs.puppet.com/puppet/latest/types/yumrepo.html

Resource collectors afford the possibility of overriding attributes of resources declared elsewhere . 资源收集器提供了覆盖在其他地方声明的资源属性的可能性。 The syntax would be: 语法为:

Package<| title == 'libvirt-nwfilter' |> {
    install_options => ['--enablerepo', 'redhat_updates']
}

That alternative avoids modifying the repository definition, and it does not require introducing any new ordering relationships. 该替代方案避免了修改存储库定义,并且不需要引入任何新的排序关系。 Beware, however, that collectors always realize any matching virtual resources. 但是请注意,收集器始终会实现任何匹配的虚拟资源。 Beware also that this approach is very powerful, and thus very easy to abuse to get yourself in trouble. 还请注意,这种方法非常强大,因此很容易被滥用以使自己陷入麻烦。 With great power comes great responsibility. 拥有权利的同时也被赋予了重大的责任。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM