简体   繁体   中英

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:

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. I tried using the ordering arrows (->) but these don't work with functions (ie with ensure_packages).

As written, the resources are applied all out of order and it takes several runs of puppet for everything to work.

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 { '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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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