Ask Your Question
0

how to run puppet based on command output

asked 2015-10-28 11:12:22 -0500

johntest gravatar image

Hello

I am looking for a way to do the following

Based on the output of a command, need to decide if I want to run the manifest.

I do not want to run the manifest when "cat /var/tmp/check.txt" contains NULL (among other things). I do want to run the manifest when "cat /var/tmp/check.txt" does not contain NULL (among other things).

Seems like its a matter of simply using grep but how to do it with Puppet?

Thanks!

edit retag flag offensive close merge delete

Comments

Do you intend to run the manifest or just the resource? e.g. exec If you only need to run the run the `exec` resource for example, you can use the conditional `unless or only_if` parameter of that resource.

lupin gravatar imagelupin ( 2015-10-28 12:08:12 -0500 )edit

@lupin The whole manifest (multiple resources) is dependent upon whether this condition meets or not. Thanks

johntest gravatar imagejohntest ( 2015-10-28 12:37:01 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2015-10-30 14:01:44 -0500

JohnsonEarls gravatar image

You can try doing this by creating a new stage that runs before the main stage, and have that stage do the test.

Note, your mileage may vary - I have not tried this outside of a very quick test.

The following example code, placed in your site.pp file, should only run the rest of the manifest if the file /var/tmp/check.txt is not empty.

stage { 'should_I_run':
    before => Stage['main']
}

class should_I_run {
    exec { "should_I_run":
        command => '/bin/test -s /var/tmp/check.txt' ,
    }
}

class { 'should_I_run':
    stage => 'should_I_run' ,
}
edit flag offensive delete link more
1

answered 2015-10-28 13:54:42 -0500

lavaman gravatar image

The way to get puppet to "respond" to the state of the system is using facter facts. You can create custom facts for whatever you want:

http://docs.puppetlabs.com/facter/lat...

You would then decide whether to apply a class based on the fact value the same way you would with any fact:

https://docs.puppetlabs.com/puppet/la...

edit flag offensive delete link more

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: 2015-10-28 11:12:22 -0500

Seen: 402 times

Last updated: Oct 30 '15