Ask Your Question
0

Is there a way of getting a file to be deployed into a variable to check and use

asked 2016-10-11 03:46:08 -0600

Kevin T gravatar image

updated 2016-11-09 22:57:08 -0600

ramindk gravatar image

Im trying to define a class that will .given a source directory structure on the master, deliver a set of files depending on the node. We used this type prior to puppet. e.g.
ROOT-DIR/etc/motd:RedHat
ROOT-DIR/etc/motd:Sles
A script would detect if your SLES or RHEL and would deliver the above files to /etc/motd for the correct OS if we then added ROOT-DIR/etc/motd:RedHat-5 then this would deliver this file to Redhat 5 boxes only and Redhat and Sles the same. If any other OS came along they would not get any file.

Wanted to reproduce this type of delivery for fixed files in puppet but for this i want to

1/ check which file to deploy 2/ create the dirs. 3/ permissions will be created later (from an array).

To solve 1 i want something like this.

$fileiwillget = some_file_source_function ( "puppet:///modules/rootdir/${name}:${::fqdn}",
"puppet:///modules/rootdir/${name}:${::operatingsystem}-${::operatingsystemmajrelease}",
"puppet:///modules/rootdir/${name}:${::operatingsystem}-${::operatingsystemrelease}",
"puppet:///modules/rootdir/${name}:${::operatingsystem}",
"puppet:///modules/rootdir/${name}")

So after this some_file_source_function has ran as per the same "source => for file" im expecting $fileiwillget will be set to the correct file name or be NULL if no file matches any of the above.

edit retag flag offensive close merge delete

Comments

1

I think you are going about this the wrong way. This is not a programming language or scripting language. This is a configuration management. Try to think of it like placing blocks down that you can stack on top of each other instead of trying to script the pieces together.

puser gravatar imagepuser ( 2016-10-12 10:07:01 -0600 )edit

I am.. Our previous configuration system delivered a fixed set of static files that were auto selected based on simple facts. Im just wanting to replicate a similar task with puppet so that for a whole bunch of BAU managed files they can be delivered from within the same puppet manifest.

Kevin T gravatar imageKevin T ( 2016-10-12 10:28:24 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-10-12 07:50:09 -0600

puser gravatar image

You need to use facts in order to determine which OS you are currently operating on. do a puppet facts in puppet and it will show you all the pre-defined facts that puppet has collected about you. For example "osfamily"

You then can reference the facts in your code like $osfamily

create a manifest that has a switch using $osfamily as the parameter (https://docs.puppet.com/puppet/latest/reference/lang_conditional.html#case-statements)

Then depending on each case define a path that the folders / files need to go in. i.e. $pathtodir Once you have that path defined, created a file resource like

file { $path_to_dir
   ... stuff
}

(from https://docs.puppet.com/puppet/latest/reference/types/file.html)

Hope that points you in the right direction.

edit flag offensive delete link more

Comments

you can use a destination file as your 'source' for a file (or for a concat fragment if you are building up a file). you also can statically serve files off of the puppet master, so you could put those files in a directory and recursively serve it out.

DarylW gravatar imageDarylW ( 2016-11-10 08:56:13 -0600 )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-10-11 03:45:15 -0600

Seen: 70 times

Last updated: Nov 09 '16