Trouble extracting raw data from custom fact

27 views
Skip to first unread message

gds

unread,
Sep 28, 2014, 9:04:35 PM9/28/14
to puppet...@googlegroups.com
Hi,
I'm new to puppet and hope somebody can help me. I have a master server with a few Mac and Windows Agents. I created a custom fact for windows that will show the current logged in users Sid. I have a manifest that will edit the HK Users registry Keys. My issue is when I run the agent it fails because it wants to place the header and other stuff not needed from the string in the path. I need the Sid only for it to work. It works if I manually insert the Sid. I'm thinking my answer is regsubst but I really don't know much about it. what I need to do is remove the first few characters and the last few. Can anyone help me out or point me in a direction? Or is there something I can do in my fact.rb to only show the raw data? Thank you in advance this one has me pulling out my hair.
Gary

Ken Barber

unread,
Sep 29, 2014, 5:35:45 AM9/29/14
to Puppet Users
regsubstr as a function will help
(https://docs.puppetlabs.com/references/latest/function.html#regsubst),
or you can do it in the fact itself using Ruby's string substitution:
http://www.ruby-doc.org/core-2.1.3/String.html#method-i-sub

The idea with both is that you need the incoming variable, a regular
expression to do the match, and then a replacement. Having said that
however, there are many options available to do string manipulation
that might help, such as split (which will convert a string into an
array by splitting on a common delimiter).

If you are struggling with the solution, perhaps you can post your
code so far, an example of what the data looks like and what you want
it to look like. I'm sure someone can then provide an example and an
explanation.

ken.
Reply all
Reply to author
Forward
0 new messages