Ask Your Question
0

How to Copy files from server based on underlying OS.!?

asked 2017-06-08 21:02:47 -0500

rohithmn03 gravatar image

Hi Team,

If OS=Linux, i need to copy splunk_forwarder_linux.tar.gz to /opt/splunk/ location.

If OS=AIX, i need to copy splunk_forwarder_aix.tar.gz to /opt/splunk/ location.

If OS=SOLARIS, i need to copy splunk_forwarder_solaris.tar.gz to /opt/splunk/ location.


Currently my Puppet code look like this:, How would like to include above feature too in my code. Please help here..!

file { '/opt/splunk/splunk_forwarder.tar.gz':  
    ensure => present,
    mode => 0600,
    source => [
        "puppet:///modules/splunk_repo/splunk_forwarder.tar.gz"
        ],
    before => Exec['unpack_splunk_forwarder.tar.gz'],
}

exec {'unpack_splunk_forwarder.tar.gz':
    unless => 'test -f /opt/splunk/splunk_forwarder/bin/splunk',
    cwd => '/opt/splunk',
    command => 'tar -zvxf splunk_forwarder.tar.gz',
}

exec {'start_splunk_service':
    command => '/opt/splunk/splunk_forwarder/bin/splunk start --accept-license',
    onlyif => "test -f /opt/splunk/splunk_forwarder/bin/splunk",
}
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2017-06-09 09:26:18 -0500

rajeevsharma gravatar image

Hi Rohit,

You need to use facters to determine the underlying OS and once OS is confirmed you can store the respective filename for further processing. Please find the sample code below (I haven't tested this but it should work)

    $tar_name = 'splunk_forwarder.tar.gz',

      case $facts['os']['family'] {
        'AIX': {
          $tar_name = splunk_forwarder_aix.tar.gz''
        }
        'Solaris': {
          $tar_name = 'splunk_forwarder_solaris.tar.gz'
        }
        'RedHat': {
          $tar_name = 'splunk_forwarder_linux_.tar.gz'
        }
}

Even as a simpler solution you can try following:

$tar_name = "splunk_forwarder_${facts['os']['family']}.tar.gz"

Hope this helps.

edit flag offensive delete link more

Comments

using "$tar_name = "splunk_forwarder_${facts['os']['family']}.tar.gz" the name of the files need be "splunk_forwarder_AIX.tar.gz"

c4f4t0r gravatar imagec4f4t0r ( 2017-06-11 05:06:20 -0500 )edit
1

answered 2017-06-09 12:29:08 -0500

rohithmn03 gravatar image

Hi Rajeev, Thanks for your help..!

I thought of doing in below way..This also looks fine right..!?

$sourcefile = $osfamily ? {
    'Solaris' => 'puppet:///modules/splunk_solaris_repo/splunk_forwarder.tar.gz',
    'RedHat' => 'puppet:///modules/splunk_redhat_repo/splunk_forwarder.tar.gz',
    'AIX' => 'puppet:///modules/splunk_aix_repo/splunk_forwarder.tar.gz',
}

file { '/opt/splunk/splunk_forwarder.tar.gz':  
    ensure => present,
    mode => 0600,
    source => $sourcefile
    before => Exec['unpack_splunk_forwarder.tar.gz'],
}

exec {'unpack_splunk_forwarder.tar.gz':
    unless => 'test -f /opt/splunk/splunk_forwarder/bin/splunk',
    cwd => '/opt/splunk',
    command => 'tar -zvxf splunk_forwarder.tar.gz',
}

exec {'start_splunk_service':
    command => '/opt/splunk/splunk_forwarder/bin/splunk start --accept-license',
    onlyif => "test -f /opt/splunk/splunk_forwarder/bin/splunk",
}
edit flag offensive delete link more

Comments

That's one of the way you can do it. Moreover we shoudl optimise the code e.g. file can be picked dynamically in file resource itself. Anyway.. plz vote if the answer was helpful.

rajeevsharma gravatar imagerajeevsharma ( 2017-06-09 18:51:30 -0500 )edit

Sure Rajeev..! Thanks for the help.

rohithmn03 gravatar imagerohithmn03 ( 2017-06-10 12:20:48 -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: 2017-06-08 21:02:47 -0500

Seen: 68 times

Last updated: Jun 09