Ask Your Question
0

firewalld: notify service not reloading service

asked 2017-02-21 07:24:47 -0500

EricL gravatar image

Hi, I wrote my own provider and type for firewalld that will simply add or remove ports or services from the public zone. The add/removes are working, but the service resource is not getting notified (or at least the firewalld service is not restarting).

current init.pp


class fwd_conf_vcs (
    $fwdportparams = $fwd_conf_vcs::params::fwdportparams,
    $fwdserviceparams = $fwd_conf_vcs::params::fwdserviceparams
    ) inherits fwd_conf_vcs::params
{
  service {
    'firewalld':
      ensure     => running,
      hasrestart => true,
      hasstatus  => true,
      enable     => true,
  }
    create_resources(firewalld_port, $fwdportparams)
    create_resources(firewalld_service, $fwdserviceparams)
    Firewalld_port <||> Firewalld_service <||> ~> Service['firewalld']
}

The reload was working when I was creating the resources in a different class, then calling that class then notifying from init.pp like this:

previous init.pp


class fwd_conf_vcs (
    $fwdportparams = $fwd_conf_vcs::params::fwdportparams,
    $fwdserviceparams = $fwd_conf_vcs::params::fwdserviceparams
    ) inherits fwd_conf_vcs::params
{
  service {
    'firewalld':
      ensure     => running,
      hasrestart => true,
      hasstatus  => true,
      enable     => true,
  }
  class { '::fwd_conf_vcs::install': } ~> Service['firewalld']
}

previous install.pp


class fwd_conf_vcs::install (
    $fwdportparams = $fwd_conf_vcs::params::fwdportparams,
    $fwdserviceparams = $fwd_conf_vcs::params::fwdserviceparams
    ) inherits fwd_conf_vcs::params
{
    create_resources(firewalld_port, $fwdportparams)
    create_resources(firewalld_service, $fwdserviceparams)
}

BUT my goal is to get everything into init.pp except for the parameters. What am I doing wrong in the current init.pp?

Thanks, Eric

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-02-21 10:40:36 -0500

DarylW gravatar image

updated 2017-02-21 15:19:05 -0500

You should pass the notify parameter in as a default set of parameters to be used by create resources.. From the documentation at https://docs.puppet.com/puppet/latest...

A third, optional parameter may be given, also as a hash:
$defaults = {
  'ensure'   => present,
  'provider' => 'ldap',
}

create_resources(user, $myusers, $defaults)

So you would want something that looks like this..

class fwd_conf_vcs (
    $fwdportparams = $fwd_conf_vcs::params::fwdportparams,
    $fwdserviceparams = $fwd_conf_vcs::params::fwdserviceparams
    ) inherits fwd_conf_vcs::params
{
  service {
    'firewalld':
      ensure     => running,
      hasrestart => true,
      hasstatus  => true,
      enable     => true,
  }

    $defaults = { notify => Service['firewalld'] }
    create_resources(firewalld_port, $fwdportparams, $defaults)
    create_resources(firewalld_service, $fwdserviceparams, $defaults)

}

--- Original answer below---

I would think that it should work how you have it but... if you are adding $fwdportparams to the create resources call, you could just merge in the notify.

class fwd_conf_vcs (
    $fwdportparams = $fwd_conf_vcs::params::fwdportparams,
    $fwdserviceparams = $fwd_conf_vcs::params::fwdserviceparams
    ) inherits fwd_conf_vcs::params
{
  service {
    'firewalld':
      ensure     => running,
      hasrestart => true,
      hasstatus  => true,
      enable     => true,
  }

    $notify_firewalld = { notify => Service['firewalld'] }
    create_resources(firewalld_port, merge($fwdportparams, $notify_firewalld))
    create_resources(firewalld_service, merge($fwdserviceparams, $notify_firewalld))

}
edit flag offensive delete link more

Comments

Thanks @DarylW, but now I am seeing this message: Debug: /Stage[main]/Fwd_conf_vcs/Firewalld_service[notify]: Nothing to manage: no ensure and the resource doesn't exist

EricL gravatar imageEricL ( 2017-02-21 12:31:16 -0500 )edit

Oh, Sorry, I had assumed you were passing default parameters in (the third argument to create_resources). I didn't realize what the 'shape' of your fwdportparams and fwdserviceparams were.... Updating my answer

DarylW gravatar imageDarylW ( 2017-02-21 15:15:02 -0500 )edit

Thank you @DarylW! that is what I was missing. Much appreciated.

EricL gravatar imageEricL ( 2017-02-22 12:39:21 -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

Stats

Asked: 2017-02-21 07:24:47 -0500

Seen: 53 times

Last updated: Feb 21