exec not executing

176 views
Skip to first unread message

Tim Dunphy

unread,
Feb 22, 2016, 2:15:00 AM2/22/16
to puppet...@googlegroups.com
Hey guys,

 I wrote an exec class for one of my modules. And for some reason, on puppet runs it's not executing.

Here's the class:

class bacula::exec {

    exec { 'create.mysql.admin.user':
    path => "/bin",
    command => "mysql -e 'grant all privileges on *.* to 'admin'@'localhost' identified by 'secret';",
    refreshonly => true,
    }

}

This is my init file:

class bacula {

    include bacula::install, bacula::service, bacula::cron, bacula::config, bacula::exec

}

Any thoughts or opininions welcomed!

Tim


--
GPG me!!

gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B

Peter Bukowinski

unread,
Feb 22, 2016, 2:40:41 AM2/22/16
to puppet...@googlegroups.com
It looks like it's the quotes in your command. The entire command is wrapped in double quotes, and the actual mysql command should be wrapped in single quotes, but isn't. Also you have admin, localhost, and secret in single quotes that aren't escaped. You will need to escape all the single quotes inside the mysql command, and also add an unescaped quote after the semicolon to match with the si glee quote after the '-e'. E.g.

command => "mysql -e 'grant all privileges on *.* to \'admin\'@\'localhost\' identified by \'secret\';'",

--
Peter
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAOZy0eky4KpzhZ4NS2BUQSSb7HK6L4HyEpPJAoRaaGK2dYW64w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Craig Dunn

unread,
Feb 22, 2016, 4:43:41 AM2/22/16
to puppet...@googlegroups.com
On Mon, Feb 22, 2016 at 8:14 AM, Tim Dunphy <bluet...@gmail.com> wrote:
> Hey guys,
>
> I wrote an exec class for one of my modules. And for some reason, on puppet
> runs it's not executing.
>
> Here's the class:
>
> class bacula::exec {
>
> exec { 'create.mysql.admin.user':
> path => "/bin",
> command => "mysql -e 'grant all privileges on *.* to 'admin'@'localhost'
> identified by 'secret';",
> refreshonly => true,
> }

You have "refreshonly" set to true, this means the exec will never run
unless something triggers a refresh event on the resource. Eg:
another resource must notify the exec resource, or the exec resource
must subscribe to another resource - it will then be triggered
whenever there is a change to the related resource.

You haven't provided any code indicating that there is a resource that
notifies your exec, I suspect thats why it's never running.

Regards

Craig

Cristian Falcas

unread,
Feb 22, 2016, 7:14:47 AM2/22/16
to puppet...@googlegroups.com
Hi,

It's because you are using "refreshonly => true,".  In order to work, you need to use something like this after you includes:

  Class['bacula::config'] ~>
  Class['bacula::exec']

If you want your exec to run after configuration changes.

Or remove the refreshonly parameter if you want it to run always.

Best regards,
Cristi



Tim Dunphy

unread,
Feb 22, 2016, 6:41:13 PM2/22/16
to puppet...@googlegroups.com
Hi Peter,

It looks like it's the quotes in your command. The entire command is wrapped in double quotes, and the actual mysql command should be wrapped in single quotes, but isn't. Also you have admin, localhost, and secret in single quotes that aren't escaped. You will need to escape all the single quotes inside the mysql command, and also add an unescaped quote after the semicolon to match with the si glee quote after the '-e'. E.g.

command => "mysql -e 'grant all privileges on *.* to \'admin\'@\'localhost\' identified by \'secret\';'",


Cool, thanks! I thought that quoting might somehow be involved. I really think this is an important part of the equation. Thanks for the tip!



You have "refreshonly" set to true, this means the exec will never run
unless something triggers a refresh event on the resource.  Eg:
another resource must notify the exec resource, or the exec resource
must subscribe to another resource - it will then be triggered
whenever there is a change to the related resource.

You haven't provided any code indicating that there is a resource that
notifies your exec, I suspect thats why it's never running.

Regards

Craig


 
It's because you are using "refreshonly => true,".  In order to work, you need to use something like this after you includes:


  Class['bacula::config'] ~>
  Class['bacula::exec']

If you want your exec to run after configuration changes.

Or remove the refreshonly parameter if you want it to run always.

Best regards,
Cristian


Craig and Christan.. thanks for your input! What I was trying to do with the 'refreshonly' statement was to get the exec statement to run only once.

How would I be able to achieve getting the exec command to run only once?

Thanks!!
Tim


For more options, visit https://groups.google.com/d/optout.

Craig Dunn

unread,
Feb 23, 2016, 3:43:18 AM2/23/16
to puppet...@googlegroups.com


On Tue, Feb 23, 2016 at 12:41 AM, Tim Dunphy <bluet...@gmail.com> wrote:

> Craig and Christan.. thanks for your input! What I was trying to do with the
> 'refreshonly' statement was to get the exec statement to run only once.
>
> How would I be able to achieve getting the exec command to run only once?

There are a number of "restrictive" attributes that will limit how/when an exec is run.  By default, with none of these, an exec will execute every time puppet runs, eg:

exec { 'foo':
  path    => "/bin",
  command => "foo --bar",
}

In order to stop the exec running on every puppet run, you need to think about when you do, or do not, want to run it.  This depends on the nature of your command and what it does.   If this command is something that should just run once to achieve a task, but never again once that task has been completed you need to think of a way to test if the task is completed or not.  That could be another command you can run to verify if you need to run the exec.  This can be achieved with onlyif / unless and takes a command as an argument.

command => 'foo --bar'
onlyif  => 'foo --has-not-run-yet'

By adding onlyif, the command foo --has-not-run-yet is issued first, the command foo --bar is only run if the first command returns 0.   Conversely, there is also unless which has the oposite behaviour to say that run this command *unless* the first command returns 0.

The second way to restrict when the command gets run is to identify a file that the command creates, that is to say, if the file exists, assume that this command has already run and don't run it, that can be done with the creates attribute

command => 'foo --bar'
creates => '/opt/created/by/foo.txt'

This will only run if the file /opt/created/by/foo.txt does not exist.

The third way is refreshonly, which you initially has in your exec.  Refreshonly will only run the command if a resource that the exec is subscribed to is changed, or if a changed resource notifies the exec.

file { '/etc/config':
  ensure   => file,
  notify   => Exec['foo']
}

The foo exec will only run if there is a change to the /etc/config file resource.

Regards
Craig

Reply all
Reply to author
Forward
0 new messages