0

Is it possible to use sh/bash variable in puppet manifest file? For example i'm using (Yes it's ugly, i know):

var=$(curl -s http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html | grep 'linux-x64.tar.gz' | awk '{print $7}' | sed 's#MB","filepath":"##g#' | sed 's#"};###' | sort -V  | tail -1 | rev | cut -c 3- | rev)
echo $var

This will give me latest Oracle java ver. 8 exact download link. My wish is to use it in tomcat.pp manifest file. Something like this:

tomcat::install { '/opt/tomcat8':
  source_url => '$var'
}

Do i have to create custom facts or is there easy way to achieve this?

Jaur
  • 85
  • 1
  • 13
  • See: [How to store linux command output into a variable in puppet](http://stackoverflow.com/q/33800565/3776858) – Cyrus Jan 10 '17 at 20:52

1 Answers1

2

Is it possible to use sh/bash variable in puppet manifest file?

Basically, no. Puppet does not rely on environment variables to interpret manifest files. Moreover, it ordinarily runs external commands in a controlled and minimal environment, and generally not via the shell. What you propose has very little chance of working, and if it happened to work then I'd characterize that as a bug, not a feature.

Do i have to create custom facts or is there easy way to achieve this?

If the datum in question is specific to the target node (which is not necessarily the case in your example) then this is indeed the role served by facts. Implementing your own facts doesn't have to be hard, though; it looks like you've already got a near complete implementation for an external fact. Put that in a file, decorate it a bit, and drop it in a suitable directory on your master, and you've got a fact.

On the other hand, if the datum is not node-specific, then you should consider storing it among your site data (i.e. in an Hiera data store), or letting the master determine it itself during catalog compilation, maybe via the generate() function.

John Bollinger
  • 160,171
  • 8
  • 81
  • 157