Ask Your Question
0

Doubt in network module from puppet forge

asked 2016-05-11 00:31:42 -0500

Chutki gravatar image

updated 2016-05-11 11:57:48 -0500

Hi,

I am working on network module and analyzing the code from the url https://github.com/razorsedge/puppet-network/blob/master/manifests/bond/static.pp , but I don't understand the below case statment

case $::operatingsystem {
    /^(RedHat|CentOS|OEL|OracleLinux|SLC|Scientific)$/: {
      case $::operatingsystemrelease {
        /^[45]/: {
          augeas { "modprobe.conf_${title}":
            context => '/files/etc/modprobe.conf',
            changes => [
              "set alias[last()+1] ${title}",
              'set alias[last()]/modulename bonding',
            ],
            onlyif  => "match alias[*][. = '${title}'] size == 0",
            before  => Network_if_base[$title],
          }
        }
        default: {}
      }

why do they use "45" value as selector facts, how it's possible for os version "RedHat|CentOS|OEL|OracleLinux|SLC|Scientific"

I referred test case for this

context 'on an older operatingsystem with /etc/modprobe.conf' do
      (['RedHat', 'CentOS', 'OEL', 'OracleLinux', 'SLC', 'Scientific']).each do |os|
        context "for operatingsystem #{os}" do
          (['4.8', '5.9']).each do |osv|
            context "for operatingsystemrelease #{osv}" do
              let :facts do {
                :osfamily               => 'RedHat',
                :operatingsystem        => os,
                :operatingsystemrelease => osv,
              }
              end
              it { should contain_augeas('modprobe.conf_bond0').with(
                :context => '/files/etc/modprobe.conf',
                :changes => ['set alias[last()+1] bond0', 'set alias[last()]/modulename bonding'],
                :onlyif  => "match alias[*][. = 'bond0'] size == 0"
              )}
            end
          end
        end
      end

why do you use ['4.8', '5.9'] for selector. please refer the url https://github.com/razorsedge/puppet-network/blob/master/spec/defines/networkbondstatic_spec.rb

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-05-11 12:05:46 -0500

That's a regular expression. /^[45]/ means "a string that begins with 4 or 5", but it doesn't mean "45". In the tests, two OS versions as strings beginning with 4 or 5 are used ('4.8' and '5.9').

When you have time you ought to do a tutorial on regular expressions.

edit flag offensive delete link more

Comments

It's a simple regular expression.
^ means match at the beginning.
[] grouping.
So match the beginning with 4 or 5.

FranzCC gravatar imageFranzCC ( 2016-05-12 00:07:07 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-05-11 00:31:42 -0500

Seen: 36 times

Last updated: May 11 '16