0

I created a module to copy one file from the master and install to agents and it works fine with code below: but now I am trying to copy 3 different files in different directory and install each one on different set of nodes. ( it is like a range of ips or dns names called A systems ...) For example: file A need to be installed on all agents in A systems nodes. File B need to be installed on all agents in B systems nodes File C need to be installed on all agents in C Systems nodes

[or you can think of it as: file1 needs to be installed on all silver systems.] and so on, for file2 and file3

class profile::ma {
    file { '/tmp/filename.sh':
        ensure  => 'present',
        replace => 'no',
        source  => 'puppet:///module/files/filename.sh',
        mode   => '0755',
        notify  => Exec['install'],
    }

    exec { 'install':
        command     => '/tmp/filename.sh -i',
        onlyif      => '/usr/bin/test ! -e /etc/filetocheck',
    }
}
Moez
  • 1
  • 2

1 Answers1

0

Assuming you mean the Puppet environment, test the $::environment variable for 'A', 'B', and 'C', then set a new variable for the source file and a new variable for the target path depending on which environment it's in.

Using an if statement:

if $::environment == 'A' {
  $source_file = 'filename_A.sh'
  $target_file = '/tmp/filename_A.sh'
} elsif $environment == 'B' {
  $source_file = 'filename_B.sh'
  $target_file = '/tmp/filename_B.sh'
# and so on
}

You can also use a case statement to test only one variable:

case $::environment {
  'A': {
    $source_file = 'filename_A.sh'
    $target_file = '/tmp/filename_A.sh'
  }
  'B': {
    $source_file = 'filename_B.sh'
    $target_file = '/tmp/filename_B.sh'
  }
}

And then use those variables instead of the hard-coded values:

file { $target_file:
    ensure  => 'present',
    replace => 'no',
    source  => "puppet:///module/files/${source_file}",
    mode   => '0755',
    notify  => Exec['install'],
}
Dominic Cleal
  • 3,205
  • 19
  • 22
  • Thank you for replying- but I should have said not environemt , it is sets of nodes... like I need file1 to be installed on all silver systems/nodes. It could that I can use lookup with dns , but struggling what is the right code – Moez Apr 24 '17 at 19:47
  • What is a "silver system"? Without more information about how you're classifying your nodes, it's not possible to give a useful answer. – Dominic Cleal Apr 25 '17 at 06:48
  • In any case, however you classify your system, this answer should be applicable - just change the `$environment` variable name to whatever you use, e.g. `$colour`. – Dominic Cleal Apr 25 '17 at 13:29