简体   繁体   English

使用sure_packages的类中资源的顺序

[英]Order of resources in a class using ensure_packages

I have a puppet class that uses the apt library and puppet's stdlib, this is the code: 我有一个使用apt库和puppet的stdlib的puppet类,这是代码:

class mymodule::gcc_48
{
  if $::lsbdistrelease == 12.04 {

    include apt
    apt::ppa { 'ppa:ubuntu-toolchain-r/test': }
    ensure_packages( ['gcc-4.8', 'g++-4.8'] )

    exec { 'update_alternatives_gcc':
      command => '/usr/sbin/update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50',
      creates => '/etc/alternatives/gcc'
    }

    exec { 'update_alternatives_gpp':
      command => '/usr/sbin/update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50',
      creates => '/etc/alternatives/g++'
    }
  }
}

I need puppet to do all of these things in the order it's written (well, except for the last two exec) but it's not clear to me how to write the dependency relationship that includes ensure_packages. 我需要木偶按其编写顺序执行所有这些操作(好,除了最后两个exec之外),但是我不清楚如何编写包含sure_packages的依赖关系。 I tried using the ordering arrows (->) but these don't work with functions (ie with ensure_packages). 我尝试使用排序箭头(->),但这些命令不适用于函数(例如,sure_packages)。

As written, the resources are applied all out of order and it takes several runs of puppet for everything to work. 如所写,所有资源都无序地应用,并且需要运行几次up才能正常工作。

I want to try to keep all of this code in the same class if that's possible. 如果可能的话,我想尝试将所有这些代码保留在同一类中。

Here is my understand. 这是我的理解。 Set the class apt::ppa as below: 将类apt::ppa设置如下:

apt::ppa { 'ppa:ubuntu-toolchain-r/test': 
    # Here puts your code for this class apt::ppa,
    before => Package['gcc-4.8', 'g++-4.8']
}

I recommend to go through this document: Learning Puppet — Resource Ordering 我建议阅读本文档: 学习木偶-资源排序

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

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