Zhonghong Yin
Zhonghong Yin

Reputation: 1

How can I execute a specific command with the puppet agent from the puppet master when needed?

I want to remotely direct the puppet agent to execute a specified command from the puppet master when needed.

I have tried this method, but it did not achieve the expected results. I define a tagged exec like this:

exec { 'mkdir_test':
  command => '/bin/mkdir -p /123',
  tag     => 'mkdirtest',
}

When I execute puppet kick -t mkdirtest, the directory located at '/123' will be successfully created. When I execute puppet kick or the puppet daemon executes periodically, the tagged exec will also be executed, but I want to filter the tagged exec. In other words, I don't want the specified command to be executed periodically, just when I need it.

Is there some way to do this with puppet?

Please excuse my poor english. Thanks.

Upvotes: 0

Views: 1140

Answers (1)

Atmesh Mishra
Atmesh Mishra

Reputation: 549

Puppet is a configuration management tool which helps you to build the infrastructure and maintain its state. So if you put an exec without conditions, it will execute the command on every run.

You can use onlyif, unless, creates and refreshonly to manage the case when you want the command to execute.

As a suggestion:

  1. To get better answer, can you elaborate on the conditions when you want the directory to be created.

  2. Usage of exec is frowned upon. You may want to use file resource to create directories. That would give you better control on conditions too.

Upvotes: 1

Related Questions