Redefine service params using Resource Collectors

asked 2015-05-12 09:01:07 -0600

rgonzalez gravatar image

updated 2015-05-12 13:16:51 -0600

Hello,

I've been struggling with this issue a while and now I decided to ask you some help. I need to redefine the 'start/restart' behavior of all classes during the execution phase (post compile phase). (I want to 'start/restart' every service through 'runcon' (selinux) command)

In the beginning I tried this:

Service <| |> { 'restart' => '/usr/bin/runcon -t initrc_t -u system_u -r system_r /sbin/service ${title} restart' }

It didn't work out. ${title} (or ${name}, whatever) is empty (all the time). Then, I made this (it's awful, but it works):

inline_template("<%
def redefineService(resource, paramType)
  found = false
  resource.parameters.each do |key, val|
    if key.to_s == paramType
      #
      # The service ALREADY has an DEFINED action (start/restart).
      #
      found = true
      break
    end
  end
  if !found and paramType == 'restart'
    #
    # DON'T redefine this param if originally the class
    # already define it (hasrestart = false).
    #
    resource.parameters.each do |key, val|
      if key.to_s == 'hasrestart'
        found = !(val.value)
        break
      end
    end
  end
  if !found
    param = Puppet::Parser::Resource::Param.new(
      :name => paramType,
      :value => '/usr/bin/runcon -t initrc_t -u system_u -r system_r /sbin/service ' << resource.title << ' ' << paramType
    )
    resource.parameters[param.name] = param
  end
end

scope.compiler.catalog.vertices.each do |resource|
  if resource.type == 'Service'
    redefineService(resource, 'start')
    redefineService(resource, 'restart')
    #puts YAML::dump(resource.parameters)
  end
end
%>")

It would be great if Resource Collectors provide those variables ($title, $name, anyway)... (Personally, I don't like the idea of use internals variables like 'scope.compiler.catalog.vertices'...) Is there any other solution?

System used (parser=future):

[root@centos6 ~]# rpm -q puppet ; uname -a
puppet-3.7.5-1.el6.noarch
Linux centos6 2.6.32-504.16.2.el6.x8664 #1 SMP Wed Apr 22 06:48:29 UTC 2015 x8664 x8664 x8664 GNU/Linux

edit retag flag offensive close merge delete