Ask Your Question

Grep a string in puppet

asked 2017-10-30 06:52:13 -0500

Anu Thakur gravatar image

I need to grep a string in a line using puppet using regular expressions. $var=['varms01' , 'varms02']

I need to run puppet exec onlyif varms01 and varms02 are not present in my config file. I am not sure How to implement this.

edit retag flag offensive close merge delete



Where does your “line” come from? Can't you just specify `unless => '/bin/grep "varms0[12]" /path/to/file'` to your Exec resource?

Kai Burghardt gravatar imageKai Burghardt ( 2017-10-30 08:10:33 -0500 )edit

yes this worked, Thanks Kai.

Anu Thakur gravatar imageAnu Thakur ( 2017-11-16 01:07:43 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-05-10 02:09:14 -0500

Daizy gravatar image

When I am trying to use the same parameter - unless, I am getting an error - "Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: no parameter named 'unless' at /etc/puppetlabs/manifests/site.pp:27 at /etc/puppetlabs/manifests/site.pp:27 "

unless => '/bin/grep "generatePublisher" C:\Program Files (x86)\ABC\ABC.exe.config'

I am trying to add below mentioned line in config file after application gets installed using the manifest. <runtime> parameter is already present in config file and here I am matching and replacing <runtime> with the below mentioned line.

  line => '  <runtime>
        <generatePublisherEvidence enabled="false"/>',
match   => "<runtime>",

Can anyone suggest how the line won't be added if generatePublisherEvidence already exists in the config file?

edit flag offensive delete link more


if it works fine for windows then I think you can change the quotes: "/bin/grep 'generatePublisher' 'C:\Program Files (x86)\ABC\ABC.exe.config'"

Mr_Sharma gravatar imageMr_Sharma ( 2018-05-10 02:44:32 -0500 )edit

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


Asked: 2017-10-30 06:52:13 -0500

Seen: 536 times

Last updated: May 10