Puppet and Mcollective yaml file changing when it shouldn't

808 views
Skip to first unread message

Zane Williamson

unread,
Dec 14, 2012, 1:06:54 AM12/14/12
to puppet...@googlegroups.com
Has anyone else ran into this?

debug: /Stage[main]/Mcollective/File[/var/tmp/facts.yaml]/content: Executing 'diff -u /var/tmp/facts.yaml /tmp/puppet-file20121214-13448-933j3r-0'
notice: /Stage[main]/Mcollective/File[/var/tmp/facts.yaml]/content: 
--- /var/tmp/facts.yaml 2012-12-14 00:53:20.000000000 +0000
+++ /tmp/puppet-file20121214-13448-933j3r-0 2012-12-14 00:55:35.000000000 +0000
@@ -93,13 +93,13 @@
   architecture: *id002
   processor14: Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz
-  type: Rack Mount Chassis
   processor20: Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz
+  type: Rack Mount Chassis
   domain: mochimedia.net
   timezone: UTC
   title: mcollective
-  diskdrives: sda
+  diskdrives: sda
   ipaddress_eth1: 10.0.8.71
   processor8: Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz
   processor11: Intel(R) Xeon(R) CPU E5-2420 0 @ 1.90GHz

When Puppet comparse the /var/tmp/facts.yaml file to the file in the Filebucket it adds some replaces some entries with an extra space.  It appears to add a couple different entries each run.  

Here is the file resource --

 "/var/tmp/facts.yaml":
      owner    => root,
      group    => root,
      mode     => 400,
      loglevel => debug,
      content  => inline_template("<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime_seconds|uptime_hours|timestamp|free)/ }.to_yaml %>")

Any thoughts or suggestions?  Seems like an odd one to me.

-Z

Zane Williamson

unread,
Dec 14, 2012, 1:27:03 AM12/14/12
to puppet...@googlegroups.com
Running Ruby 1.8.7... I believe this issue started when I upgraded from 1.8.5, but I am not 100% positive.

Zane Williamson

unread,
Dec 14, 2012, 2:05:14 AM12/14/12
to puppet...@googlegroups.com
Well I think I came up with a decent hack.

content  => inline_template("<%= scope.to_hash.reject { |k,v| k.to_s =~ /(uptime_seconds|uptime_hours|timestamp|free)/ }.to_yaml.sort { |a,b| b <=> a} %>")

the sort and then inverse (to make sure the "---/n" is on top for the fact file format) seems to stop to_yaml from adding spaces.


On Thursday, December 13, 2012 5:06:54 PM UTC-8, Zane Williamson wrote:

Zane Williamson

unread,
Dec 14, 2012, 3:02:13 AM12/14/12
to puppet...@googlegroups.com
Actually, applying sort doesn't work.  It doesn't sort the file properly and the spacing and line creation is incorrect.

I looked at other similar posts and it appears to be an issues with Ruby with no direct solution besides stopping puppet from managing this file.


On Thursday, December 13, 2012 5:06:54 PM UTC-8, Zane Williamson wrote:

R.I.Pienaar

unread,
Dec 14, 2012, 9:25:22 AM12/14/12
to puppet...@googlegroups.com


----- Original Message -----
> From: "Zane Williamson" <zane.wi...@gmail.com>
> To: puppet...@googlegroups.com
> Sent: Friday, December 14, 2012 3:02:13 AM
> Subject: [Puppet Users] Re: Puppet and Mcollective yaml file changing when it shouldn't
>
> Actually, applying sort doesn't work. It doesn't sort the file
> properly and the spacing and line creation is incorrect.
>
> I looked at other similar posts and it appears to be an issues with
> Ruby with no direct solution besides stopping puppet from managing
> this file.

yeah, ruby hashes does not have an order in older versions of ruby, this
is quite a horrible hack but some have reported success:

<%=
def sort_yaml(obj)
arr = obj.sort
out = "---\n"
arr.each do |element|
entry = {element[0] => element[1]}
out += entry.to_yaml.to_a[1..-1].join + "\n"
end
out
end

sort_yaml(scope.to_hash.reject {|k,v| k.to_s =~ /^(uptime.*|rubysitedir|_timestamp|memoryfree|extlookup_precedence|extlookup_datadir|swapfree|title|name|caller_module_name|module_name)$/ })
%>

Louis Coilliot

unread,
Dec 14, 2012, 9:34:12 AM12/14/12
to puppet...@googlegroups.com
This works also :

content => inline_template("<%= Hash[scope.to_hash.reject { |k,v| k.to_s =~ /(uptime|timestamp|memory|free|swap)/ }.sort].to_yaml %>")

It does not sort but keep the fact list in the same order.

Louis Coilliot
--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/puppet-users/-/eE8sQojblMUJ.
To post to this group, send email to puppet...@googlegroups.com.
To unsubscribe from this group, send email to puppet-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/puppet-users?hl=en.

phundisk

unread,
Dec 14, 2012, 2:43:52 PM12/14/12
to puppet...@googlegroups.com
Thank you, I was having the same issue as you were.  Puppet Dashboard was complaining that a node was changing every time because of this file that changed slightly.
_____________________________________________________
This email and any files transmitted with it are confidential and intended solely for the addressee.  If you received this email in error, please do not disclose the contents to anyone; kindly notify the sender by return email and delete this email and any attachments from your system.

© 2011 Currensee Inc. is a member of the National Futures Association (NFA) Member ID 0403251 | Over the counter retail foreign currency (Forex) trading may involve significant risk of loss. It is not suitable for all investors and you should make sure you understand the risks involved before trading and seek independent advice if necessary. Performance, strategies and charts shown are not necessarily predictive of any particular result and past performance is no indication of future results. Investor returns may vary from Trade Leader returns based on slippage, fees, broker spreads, volatility or other market conditions.

Currensee Inc | 54 Canal St 4th Floor | Boston, MA 02114 | +1.617.624.3824

Zane Williamson

unread,
Dec 18, 2012, 6:34:16 AM12/18/12
to puppet...@googlegroups.com
Thank you for the recommendations.  I am going to give them a try and see how they work out in production.

Thanks!
Zane


On Thursday, December 13, 2012 5:06:54 PM UTC-8, Zane Williamson wrote:
Message has been deleted

Dave Ta

unread,
Feb 3, 2013, 5:53:40 AM2/3/13
to puppet...@googlegroups.com
Try using an erb template for your facts.yaml file.  Its working well for me so far.

# facts.yaml.erb
<%=
    yaml = ["---"]
    keys = scope.to_hash.keys.reject {|k| k.to_s =~ /(uptime_seconds|uptime_hours|timestamp|free)/}
    keys.sort.each {|k| yaml << "#{k}: #{scope.lookupvar(k).to_s}"}
    yaml.join("\n   ")
%>
 
# manifest
file{"/etc/mcollective/facts.yaml":
  owner    => root,
  group    => root,
  mode     => 400,
  loglevel => debug,  
  content => template("mcollective/facts.yaml.erb");
}

R.I.Pienaar

unread,
Feb 3, 2013, 6:14:40 AM2/3/13
to puppet...@googlegroups.com


----- Original Message -----
> From: "Dave Ta" <davetak...@gmail.com>
> To: puppet...@googlegroups.com
> Sent: Sunday, February 3, 2013 6:53:40 AM
> Subject: [Puppet Users] Re: Puppet and Mcollective yaml file changing when it shouldn't
>
> Try using an erb template for your facts.yaml file. Its working well for
> me so far.
>
> # facts.yaml.erb
> <%=
> yaml = ["---"]
> keys = scope.to_hash.keys.reject {|k| k.to_s =~
> /(uptime_seconds|uptime_hours|timestamp|free)/}
> keys.sort.each {|k| yaml << "#{k}: #{scope.lookupvar(k).to_s}"}
> yaml.join("\n ")
> %>

might have some quoting issues here with facts that have : in them etc, this one
addresses that:

<%=
facts = scope.to_hash.reject {|k,v| k.to_s =~ /^(uptime.*|rubysitedir|_timestamp|memoryfree)$/ }

facts.keys.sort.map {|f| {f => facts[f]}.to_yaml.to_a[1..-1].join}.join("\n")
%>


>
> # manifest
> file{"/etc/mcollective/facts.yaml":
> owner => root,
> group => root,
> mode => 400,
> loglevel => debug,
> content => template("mcollective/facts.yaml.erb");
> }
>
> --
> 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...@googlegroups.com.
> To post to this group, send email to puppet...@googlegroups.com.
> Visit this group at http://groups.google.com/group/puppet-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

Zane Williamson

unread,
Feb 15, 2013, 6:08:41 AM2/15/13
to puppet...@googlegroups.com
Excellent, the erb template method is working great.  Thank you for the information.


On Thursday, December 13, 2012 5:06:54 PM UTC-8, Zane Williamson wrote:

Robert Reilly

unread,
May 13, 2014, 5:00:05 PM5/13/14
to puppet...@googlegroups.com
All, I found this post as I was having the same issue. I added the template and the first run it buckets the file because it is once again changed but not the second time, the third time it runs it complains it cannot Filebucket the file because it exists.
here is the template
<%=
  facts = scope.to_hash.reject {|k,v| k.to_s =~ /^(uptime.*|rubysitedir|_timestamp|memoryfree|extlookup_precedence|extlookup_datadir|swapfree|title|name|caller_module_name|module_name|last_run)$/ }
  facts.keys.sort.map {|f| {f => facts[f]}.to_yaml.to_a[1..-1].join}.join("\n")
%>

here is the error from trace on the client.
Error: /Stage[main]/Main/File[/etc/mcollective/facts.yaml]/content: change from {md5}1b7af6a10f71df6e3ac2eece4d5f14d5 to {md5}8bc466df9567f5e0ccc12581e4fc9c3c failed: Could not back up /etc/mcollective/facts.yaml: Error 400 on SERVER: File exists - /var/lib/puppet/bucket/1

Thanks !
Robert

Robert Reilly

unread,
May 13, 2014, 5:06:19 PM5/13/14
to puppet...@googlegroups.com
ruby version 1.8.7...
Reply all
Reply to author
Forward
0 new messages