Ask Your Question
0

If running then not exec

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

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.

Code:

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=198.51.100.0/24 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
0

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

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 https://forge.puppet.com/garethr/docker 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

Stats

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

Seen: 41 times

Last updated: Aug 01 '16