Ask Your Question

else clause in module not working

asked 2018-10-29 00:52:35 -0600

ThatGuyAUS gravatar image

updated 2018-10-29 07:50:57 -0600

DarylW gravatar image

Bare with me as i'm still new to Puppet. I'm currently writing a module to install an agent on a Windows machine/s. below is the code:

class agent {

  if $facts['agentisnotinstalled'] {
    include agent::install
  else {
    file { 'c:\puppetfiles\agent.msi':
    ensure => absent,

essentially it pulls a fact, within the module, that returns as TRUE that the agent is NOT installed. under the module agent::install it then copies the msi to the client and installs the package, now what i'm wanting it to do, is on a second run, it would return FALSE, the agent IS installed, and delete the MSI package as it is not required on the file system anymore. unfortunately, it doesn't seem to be running the 'else' block . the reason i'm doing this is that, if we have multiple different modules all running different installation packages, we'lll end up with installer files kept on the system, and am just trying to do cleanup along the way built into modules

edit retag flag offensive close merge delete


Are you sure your `$facts['agent_is_not_installed']` returns `false` the second time? Maybe, for debugging, insert a statement emitting a message telling you its actual value. I just doubt it. Also, this design is rather bad than useful. In Puppet you _describe_ a (finite) state [not processes].

Kai Burghardt gravatar imageKai Burghardt ( 2018-10-30 06:21:01 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2018-11-07 03:30:10 -0600

deric gravatar image

What you're trying to accomplish is an anti-pattern in Puppet.

  package { 'agent':
    ensure  => present,

 file {'some_installation_file':
  ensure  => absent,
  require => Package['agent'],

Manifests should be written in a manner where all operations could be accomplished in a single run. require => Package['agent'], ensures ordering of operations. First the agent package will be installed, the Puppet will remove temporary file.

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: 2018-10-29 00:52:35 -0600

Seen: 147 times

Last updated: Nov 07