I'm trying to pass ensure=> values in variables (and set resource defaults 
conditionally) and it doesn't seem to work that way. If there's some way of 
getting this working I am very happy to hear about it.

In my site.pp I have this sort of thing:

if $::devstyle and str2bool($::devstyle) {
  notify { 'et': message => 'devstyle on' }

  File {
    ensure => present,
  }
  $filefe = present
}
else {
  $filefe = file
}

The idea is that puppet will treat all file resources as ensure=>present 
anywhere that devstyle=true (it's an external fact). I do see the notify text 
in syslog when the agent run proceeds.

However, two things are not happening:

1) not getting the resource default when the resource does not have ensure=>
  (puppet reverts my manually modified file)

2) ensure => $::filefe is not ensuring 'present' when devstyle=true (special 
corporate bits censored out):

notify { 'mrt1':
  message => "filefe=${::filefe}"
}

file { '/etc/mrouted.conf':
  ensure  => $::filefe,
  content => "whatever\n",
}

The notify reports the expected value of $::filefe is as I expect, but the 
file's contents are still managed.

Apr 30 13:25:30 myhost puppet-agent[28675]: 
(/Stage[main]/Mrouted/Notify[mrt1]/message) defined 'message' as 
'filefe=present'

Apr 30 13:25:26 myhost puppet-agent[28675]: 
(/Stage[main]/Mrouted/File[/etc/mrouted.conf]/content) content changed 
'{md5}35195dd2d3f40d5bbd647c642919c86a' to 
'{md5}f5c4f579df6e0d5b088f8811f556c73b'


On the bright side, it works exactly the same way without 
hiera_include()/modules/etc.

$ cat /tmp/file1
my contents

$ cat /tmp/t.pp
$dire = directory
$file= present
#$file = file

class myclass {
  notice("dire=${::dire} and file=${::file}")
  file { '/tmp/dir1':
    ensure => $::dire,
  }
  file { '/tmp/file1':
    ensure  => $::file,
    content => "file1 contents\n",
  }
}

include ::myclass

$ puppet apply /tmp/t.pp
Notice: Scope(Class[Myclass]): dire=directory and file=present
Notice: Compiled catalog for cwl.hostopia.com in environment production in 0.07 
seconds
Notice: /Stage[main]/Myclass/File[/tmp/file1]/content: content changed 
'{md5}579f6bb5beadcc02c12382fd65f583fb' to 
'{md5}a3814bc196b27f6b4c6409d2a0e5899f'
Notice: Finished catalog run in 0.15 seconds

$ cat /tmp/file1
file1 contents

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/20150430180003.GA7549%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.

Reply via email to