0

I don't know to solve this problem. I want to run postmap command after creation or change of a file.

        ensure => 'present',
        value  => 'hash:${postfix_path}${virtual_alias_maps}',
        #notify => Exec['generate ${postfix_path}${virtual_alias_maps}']   }

      file {"${name}":
        ensure  => $ensure,
        require => [File[$name], Exec["generate ${name}"]],   }

      exec { 'generate ${name}':
        command     => 'postmap ${name}',
        path        => $::path,
        subscribe   => File[$name],
        refreshonly => true   
     }
´´´

1 Answer 1

0

Single-quoted strings are not subject to variable interpolation. Use double-quoted strings instead if you want interpolation, like this:

  exec { "generate ${name}":
    command     => "postmap ${name}",
    path        => $::path,
    subscribe   => File[$name],
    refreshonly => true   
 }

That also assumes that variable $::path actually contains a path suitable for locating the postmap executable. That's conceivable, but I'm inclined to doubt that it is actually the case for you. Is there so much uncertainty about where that executable is installed (and where any external programs it executes are installed) that you cannot provide a literal path that will suffice?

Additionally, there are separate issues with the file declaration presented:

      file {"${name}":
        ensure  => $ensure,
        require => [File[$name], Exec["generate ${name}"]],   }
  • the declared File resource expresses a dependency on itself. This creates a dependency loop that will cause catalog building to fail.

  • the declared File resource expresses a dependency on Exec["generate ${name}"], which resource also expresses a dependency on it (subscribe has this among its effects). This constitutes another, separate dependency loop that will cause catalog building to fail. Between this and the previous, you probably just want to drop the require attribute altogether.

  • you are ensuring the file to a state indicated by variable $ensure. Although that is not inherently wrong, you need to be sure that the effects are correct for all cases. In particular, if you ensure the file absent then it is probably incorrect for the Exec to be triggered when the file is brouught into that state. If it is possible to ensure the file to be a directory then that, too, probably would not play nicely with the effect of the Exec.

Also, you are not directly managing the content of the file, its ownership, or its mode. That may be ok, and maybe even desirable, but I recommend considering whether it would be feasible to put Puppet in full control of the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.