Ask Your Question
0

how to deploy different files to multiple OS

asked 2018-01-18 14:31:19 -0600

ck12986 gravatar image

I an trying to install two different repo files one corresponding to red hat 6 and the other to red hat 7, how do I configure my init.pp file to make this distinction in puppet.

edit retag flag offensive close merge delete

3 Answers

Sort by ยป oldest newest most voted
2

answered 2018-01-20 15:40:56 -0600

Red Cricket gravatar image

updated 2018-01-20 21:16:56 -0600

You could also leverage hiera.

Your hiera.yaml would have a line in like this:

...
hierarchy:
...
  - name: "Per-OS defaults"
    path: "os/%{facts.os.name}.yaml"
...

And then in "os/Ubuntu.yaml" you would have:

---
your_puppet_class::repo_file_name: '/etc/whatever/ubuntufile'
your_puppet_class::repo_file_contents: |
  blah blah ubuntu blah

And then in "os/Centos.yaml" you would have:

---
your_puppet_class::repo_file_name: '/etc/whatever/centosfile'
your_puppet_class::repo_file_contents: |
  blah blah centos blah

Then you would have a puppet code that looks like this:

class your_puppet_class (
   $repo_file_name,
   $repo_file_contents,
) {
file { $repo_file_name:
      ensure  => 'file',
      content => $repo_file_contents,
    }
}
edit flag offensive delete link more
1

answered 2018-01-19 11:21:23 -0600

DynamicD gravatar image

updated 2018-01-20 11:14:35 -0600

IMHO the easiest way to handle this is with the "case" statement. You can then fill in an option per match with a "default" for remaining conditions. Something like:

case $facts['os']['name'] {
  Ubuntu: { 
    file { 'myfile' :
      ensure  => 'file',
      content => file('modulename/ubuntufile'),
    }
  }
  Centos: {
    file { 'myfile' :
      ensure  => 'file',
      content => file('modulename/centosfile'),
    }
  }
}
edit flag offensive delete link more
1

answered 2018-01-19 04:04:53 -0600

rajeevsharma gravatar image

Hi, this can be done using Facts. These facts are collected from all puppet nodes which can be used in your code to achieve your goal.

operatingsystem                     OracleLinux 

operatingsystemmajrelease           6 

operatingsystemrelease              6.8

Sample code:

if ($OperatingSystem == "Linux") { 
   $message = "This machine OS is of the type $OperatingSystem \n" 
} else { 
   $message = "This machine is unknown \n" 
} 

file { "/tmp/machineOperatingSystem.txt": 
   ensure => file, 
   content => "$message" 
}

Above Facts and their values can be used in your manifest to define OS specific or os release specific code. Please find detail example here.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2018-01-18 14:31:19 -0600

Seen: 58 times

Last updated: Jan 20