0

I am trying to write an if clause to do something according to the current status of a machine. I understand according to puppet's philosophy catalogs evaluate and push to the machines before they run in machines.

To keep consistency I would like to use puppet instead of using custom scripts (like bash). I need this kind of behavior in puppet if it would be possible.

Here's an example: puppet agent runs every hour on a machine: - pulling a repo to see any new commit - searching for a specific word in the repo - if found: trigger some dependencies - if not found: trigger other dependencies

My problem: 'If clause' already had evaluated in puppet server so there is not any way to make dependencies in the desired order according to the machine status.

Any idea?

Ehsan
  • 1
  • 1

1 Answers1

2

You have to make a Puppet Fact that shows the state of the machine you are interested in, then base your 'if clause' on that fact. Have a look at these:
https://puppet.com/docs/facter/3.5/custom_facts.html
https://puppet.com/docs/puppet/5.3/lang_facts_and_builtin_vars.html

Scottie H
  • 227
  • 2
  • 10
  • What "state" are you looking for? – Scottie H Feb 20 '19 at 18:31
  • Yes. Facts evaluate before 'if clause' so there is no way a fact assign with a new value after one of the resources is changed. e.g. Consider the following scenarios: A, B, C, D are resources. A[] ~> B[] ~> C[] -- if B[] found the content then call C[] A[] ~> B[] ~> D[] -- if B[] not found the content then call D[] Which A[] pulls from a repo then B[] according to the newest commit, read a file and trigger either C[] or D[]. I need B[] trigger different resources after A pull the repo. – Ehsan Feb 20 '19 at 18:36
  • 1
    I have told may the best option would be using CI tool like Jenkins or using cron taks or even using Exec with 'refresh only'. – Ehsan Feb 20 '19 at 18:39