Ask Your Question

If running then not exec

asked 2016-08-01 03:01:10 -0600

wdcapl gravatar image

Hello Puppet team,

I know that puppet's nature does not allow normal if statements.

I want to achieve something like: If service is running then don't Exec ['restart_daemon'] else if running then continue with no exception.


notice("Reload systemd...")
exec {'systemd_reload':
  command => 'systemctl daemon-reload',
  path    => '/usr/local/bin/:/bin/',
  logoutput => $log_debug,
  require => File['/root/.docker/config.json'],
  before => Exec['systemd_docker_restart']

notice("Restart docker...")
exec {'systemd_docker_restart':
  command => 'systemctl restart docker',
  path    => '/usr/local/bin/:/bin/',
  logoutput => $log_debug,
  require => Exec['systemd_reload'],
  before => Service['docker']

notice("Ensure docker is running...")
service {
        "docker":  ensure => "running",
        require => Exec['systemd_docker_restart'],

exec {'docker_csnet_create':
  command => 'docker network create --subnet= csnet',
  path    => '/usr/local/bin/:/bin/:/usr/bin/',
  logoutput => $log_debug,
  require => Service['docker'],

Means I don't want to restart docker if it's already running. In fact it would be awesome if I could go a different path if it's running.

Can you please provide an example / help out?

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2016-08-01 22:35:06 -0600

DarylW gravatar image

You need to think about how to describe your system, and use that to allow puppet to make the system how you want it to be. You need a resource to describe 'this service should be running', while you describe how to restart it if it's not running, and how to tell (status) if it is running or not.

Most of what you need is probably provided by the module. It has support for creating networks, ensuring certain containers are running, and handling the docker install and service.

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


Asked: 2016-08-01 03:00:46 -0600

Seen: 76 times

Last updated: Aug 01 '16