On Fri, May 01, 2015 at 05:58:37AM -0700, jcbollinger wrote:
> 
> 
> On Thursday, April 30, 2015 at 1:00:45 PM UTC-5, Christopher Wood wrote:
> >
> > 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. 
> >
> >
> 
> Yes.  You have specified that it should be so.
> 
> Evidently you have a misconception about the meaning of 'ensure => 
> present'.  That does *not* mean "ignore all the other properties specified 
> for this resource".  It means only "I don't care whether the target is a 
> directory, symlink, or regular file, so long as it's present".  It is 
> unusual to combine that with any value for 'content', as doing so implies 
> that you *do* care what kind of filesystem object it is: it must be a 
> regular file or a symlink pointing to a regular file.
> 
> Possibly you are looking for `replace => false`, instead.

Yes, that was exactly it, thank you.


For posterity, it works with this in site.pp (3.7.2 master/agent):

if $::devstyle and str2bool($::devstyle) and $::cluster and 'dev' == $::cluster 
{
  File {
    replace => false,
  }
  notify { 'devstyle':
    message => 'Not managing file contents, devstyle=true.',
  }
}

And this in the inventory module:

if 'dev' == $::cluster {
  $dscontents = "devstyle=true\n"
}
else {
  $dscontents = "devstyle=false\n"
}

file { '/etc/facter/facts.d/devstyle.txt':
  content => $dscontents,
}

Any developer wanting a real agent run on their pet host will remove that file 
and have a production-style agent run.

I will flatter myself by thinking that other people might also run into this. 
In that spirit I filed DOCUMENT-336 for a minor touchup.

https://tickets.puppetlabs.com/browse/DOCUMENT-336


Also for the next person to happen across this thread, there's a warning if the 
file is a symlink or something else while this behaviour applies:

$ ls -ld /tmp/this
lrwxrwxrwx 1 cwood cwood 4 May  1 10:48 /tmp/this -> that
$ cat /tmp/z.pp
file { '/tmp/this':
  ensure => present,
  content => "this file has a string in it\n",
  #  replace => false,
}
$ puppet apply /tmp/z.pp
Notice: Compiled catalog for cwl in environment production in 0.07 seconds
Warning: /Stage[main]/Main/File[/tmp/this]: Ensure set to :present but file 
type is link so no content will be synced
Notice: Finished catalog run in 0.10 seconds



> 
> John
> 
> -- 
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/4b6d2e84-5b00-4af6-90fa-86b2a4fcab6c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/20150501151518.GA15753%40iniquitous.heresiarch.ca.
For more options, visit https://groups.google.com/d/optout.

Reply via email to