Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is it possible to pass puppet resource references to other resources? My use-case is to build a jenkins build pipeline with puppet. To chain jenkins jobs into a pipeline I need to pass the successor job to a job. A subset of the definition is:

jobs::build { "Build ${release_name}":
  release           => $release_name,
  jenkins_jobs_path => $jenkins_jobs_path,
   successors        => 'Deploy',
}

jobs::deploy { "Deploy ${release_name}":
  release           => $release_name,
  jenkins_jobs_path => $jenkins_jobs_path,
  successors        => 'Smoke Test',
}

In the def you see that I define the successors by name, i.e. 'Deploy' and in case of the second job 'Smoke Test'. What I'd like to do is to pass a reference to a resource and extract the name from it:

jobs::build { "Build ${release_name}":
  release           => $release_name,
  jenkins_jobs_path => $jenkins_jobs_path,
   successors       => Jobs::Deploy["Deploy ${release_name}"],
}

jobs::deploy { "Deploy ${release_name}":
  release           => $release_name,
  jenkins_jobs_path => $jenkins_jobs_path,
  successors        => Jobs::Smoke_test["Smoke Test ${release_name}"],
}

And then within the jobs::deploy and jobs::build definition I'd access the resource by reference and query for it's type, etc..

Is it possible to achieve this in puppet?

share|improve this question

3 Answers 3

This sounds more like a job for Mcollective than for Puppet. Very broadly put, with Puppet you model state, while with Mcollective you model activity. Writing an MCollective agent that orchestrates your build pipeline is probably the better way to go, if I understand your requirements correctly. Puppet won't help you much here.

share|improve this answer

If I understand correctly, the successors parameter has nothing to do with Puppet's before meta parameter, but is there to define job relationships for Jenkins.

That being said, what you are asking is not possible with Puppet. You can't query values from resource reference, even if you could pass them to a definition as a parameter.

I think you could manage with:

jobs::build { "Build ${release_name}":
  release           => $release_name,
  jenkins_jobs_path => $jenkins_jobs_path,
  successors        => "Deploy ${release_name}",
}

or with tags and <| |>operators. But this depends totally on the contents of jobs::build definition and the configuration needed for Jenkins.

share|improve this answer

Yes, instead of successors, use the before meta parameter. All resources in Puppet allow the use of four parameters that establish ordering. before, require, subscribe, and notify are the four relationship meta-parameters. Subscribe and notify are particularly useful for signaling if a resource causes another resource to refresh.

Please see the Puppet language guide for more information. Specifically, the keywords "ordering" and "relationships" should help you find the information you need to solve this problem.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.