Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variable to puppet on commandline

I'm trying to get TeamCity to trigger a deployment with puppet via the commandline using puppet.bat on Windows.

In Teamcity I'm calling this using a Command Line runner, with Command executable: C:\Program Files (x86)\Puppet Labs\Puppet\bin\puppet.bat Command parameters: apply myexample.pp

What I would like to do is also pass the build number from TeamCity as well so I can use this within myexample.pp

Is this possible?

UPDATE: Code used for Custom Fact which was the accepted answer below.

require 'open-uri'

$uri = URI.parse("http://teamcity/guestAuth/app/rest/buildTypes/id:    <BUILDID>/builds/status:SUCCESS/number")
$version = $uri.read

Facter.add("latestbuildversion") do
  setcode do    
    $version
  end
end
like image 643
Grant Trevor Avatar asked Apr 09 '13 12:04

Grant Trevor


People also ask

How do I pass a variable in command prompt?

To pass variable values via the command line, use the PrjVar ( pv ) or PSVar ( psv ) arguments for the project and project suite variables respectively. Variable values you pass via the command line are temporary.

Which command can be used to print specific configuration of a resource instance in puppet?

A commented list of all configuration options can also be generated by running puppet with '--genconfig'.


2 Answers

To pass a value through the command line it needs to be an environment variable, prefixed by FACTER_.

So, FACTER_foo will turn into $::foo.

like image 68
Marga Manterola Avatar answered Sep 20 '22 15:09

Marga Manterola


I think you'd want to do this via custom facts, which this conversation addresses.

like image 24
Kyle Campos Avatar answered Sep 16 '22 15:09

Kyle Campos