Re: [Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-13 Thread Rob Nelson
There's also `last reboot -1`, add your favorite timestamp format with -T :)


Rob Nelson
rnels...@gmail.com

On Fri, Jan 13, 2017 at 6:27 AM, Thomas Müller 
wrote:

>
>
> Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
>>
>> Hi there,
>>
>> probably a pretty easy to answer question.
>>
>> I want to try out adding custom facts. My first custom fact should be
>> "lastrebootdate"
>>
>> My code looks like this:
>>
>> Facter.add(:lastrebootdate) do
>>   setcode do
>> Facter::Util::Resolution.exec("/usr/bin/who -b |awk '{print $3}'")
>>   end
>> end
>>
>> Running the command on the system returns "2017-01-30"
>>
>>
>>
> just a random thought: instead of calling who you could take the already
> existing uptime fact and just calculate the date with ruby time/date
> functions.
>
> - Thomas
>
>
> --
> 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/41898ce0-c5e3-472f-98f9-eb4fbae47aa8%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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAC76iT9-egYN4OeKg9qk%3DrwxMhRPgON-UMxyPRKvZJPvt%3DikVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-13 Thread Thomas Müller


Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
>
> Hi there,
>
> probably a pretty easy to answer question.
>
> I want to try out adding custom facts. My first custom fact should be 
> "lastrebootdate"
>
> My code looks like this:
>
> Facter.add(:lastrebootdate) do
>   setcode do
> Facter::Util::Resolution.exec("/usr/bin/who -b |awk '{print $3}'")
>   end
> end
>
> Running the command on the system returns "2017-01-30"
>
>
>
just a random thought: instead of calling who you could take the already 
existing uptime fact and just calculate the date with ruby time/date 
functions.

- Thomas
 

-- 
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/41898ce0-c5e3-472f-98f9-eb4fbae47aa8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-10 Thread Rob Nelson
Thanks for the correction. Definitely way off base on that, my apologies
for the erroneous claims!


Rob Nelson
rnels...@gmail.com

On Tue, Jan 10, 2017 at 4:46 PM, Stefan Schulte  wrote:

> Hey Rob,
>
> variable interpolation in strings in ruby is actually done with
> #{some_var}, so the following snippet
>
> #!/usr/bin/ruby
>
> "Hello World".match(/Hello (.*)/)
>
> puts $1
> puts "$1"
> puts "#{$1}
>
> actually returns
>
> World
> $1
> World
>
> As you can see "$1" does not interpolate to an earlier match.
>
> On 10.01.2017 21:14, Rob Nelson wrote:
> > At a guess, dollar signs inside double quotes interpolate, so it's
> > extremely possible that somewhere earlier in the ruby run, $3 matched
> > "Jan" somewhere and that was reused in your awk command. In the latter
> > usage there's probably no $6 (that's a lot of matches!) or it amazingly
> > has the value '$6'. I would definitely be more careful about escaping
> > any dollars inside of double quoted strings that are passed to exec(),
> > system(), or similar functions, as escaping that can be a nightmare when
> > the stars align during your design but not weeks later during your usage.
> >
> > On Tuesday, January 10, 2017 at 12:24:45 PM UTC-5, Denny wrote:
> >
> > Tried out another customfact "lastyumupdate" which looks like:
> >
> > |
> > Facter.add(:lastyumupdate) do
> >   setcode do
> > Facter::Util::Resolution.exec("yum history |grep -E '^.*(Update|
> > U).*$' |head -n 1 |awk '{print $6}'")
> >   end
> > end
> > |
> >
> > This one returns on command line "2017-01-10" AND sets the fact
> correct
> >
> > |
> > $ puppet facts |grep last
> > "lastrebootdate": "Jan",
> > "lastyumupdate": "2017-01-10",
> > |
> >
> >
> > Any help is appreciated :)
> >
> >
> > Denny
> >
> > Am Dienstag, 10. Januar 2017 17:47:36 UTC+1 schrieb Denny:
> >
> > PS: I'm running facter 3.5.0 with puppet 4.8.1 on CentOS 7
> >
> >
> > Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
> >
> > Hi there,
> >
> > probably a pretty easy to answer question.
> >
> > I want to try out adding custom facts. My first custom fact
> > should be "lastrebootdate"
> >
> > My code looks like this:
> >
> > |
> > Facter.add(:lastrebootdate) do
> >   setcode do
> > Facter::Util::Resolution.exec("/usr/bin/who -b |awk
> > '{print $3}'")
> >   end
> > end
> > |
> >
> > Running the command on the system returns "2017-01-30"
> >
> > Deploying my fact on a puppet node and running the puppet
> > agent returns "Jan".
> >
> > |
> > $ puppet facts |grep lastrebootdate
> > "lastrebootdate": "Jan",
> > |
> >
> > What did I miss?
> >
> > Thank you,
> >
> > Denny
> >
> > --
> > 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/1fe52550-
> e656-415a-9197-a692d397c8bc%40googlegroups.com
> >  e656-415a-9197-a692d397c8bc%40googlegroups.com?utm_medium=
> email_source=footer>.
> > 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 puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/puppet-users/ccb700cd-6bf1-14dc-84cf-9b75d7181eca%40posteo.de.
> 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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAC76iT8Q1H%2Bzi%2B1mW5ss7EoDn21Nu8QJWOB%2BhGkkyKmuA0%3DJpQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-10 Thread Stefan Schulte
Hey Rob,

variable interpolation in strings in ruby is actually done with
#{some_var}, so the following snippet

#!/usr/bin/ruby

"Hello World".match(/Hello (.*)/)

puts $1
puts "$1"
puts "#{$1}

actually returns

World
$1
World

As you can see "$1" does not interpolate to an earlier match.

On 10.01.2017 21:14, Rob Nelson wrote:
> At a guess, dollar signs inside double quotes interpolate, so it's
> extremely possible that somewhere earlier in the ruby run, $3 matched
> "Jan" somewhere and that was reused in your awk command. In the latter
> usage there's probably no $6 (that's a lot of matches!) or it amazingly
> has the value '$6'. I would definitely be more careful about escaping
> any dollars inside of double quoted strings that are passed to exec(),
> system(), or similar functions, as escaping that can be a nightmare when
> the stars align during your design but not weeks later during your usage.
> 
> On Tuesday, January 10, 2017 at 12:24:45 PM UTC-5, Denny wrote:
> 
> Tried out another customfact "lastyumupdate" which looks like:
> 
> |
> Facter.add(:lastyumupdate) do
>   setcode do
> Facter::Util::Resolution.exec("yum history |grep -E '^.*(Update|
> U).*$' |head -n 1 |awk '{print $6}'")
>   end
> end
> |
> 
> This one returns on command line "2017-01-10" AND sets the fact correct
> 
> |
> $ puppet facts |grep last
> "lastrebootdate": "Jan",
> "lastyumupdate": "2017-01-10",
> |
> 
> 
> Any help is appreciated :)
> 
> 
> Denny
> 
> Am Dienstag, 10. Januar 2017 17:47:36 UTC+1 schrieb Denny:
> 
> PS: I'm running facter 3.5.0 with puppet 4.8.1 on CentOS 7
> 
> 
> Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
> 
> Hi there,
> 
> probably a pretty easy to answer question.
> 
> I want to try out adding custom facts. My first custom fact
> should be "lastrebootdate"
> 
> My code looks like this:
> 
> |
> Facter.add(:lastrebootdate) do
>   setcode do
> Facter::Util::Resolution.exec("/usr/bin/who -b |awk
> '{print $3}'")
>   end
> end
> |
> 
> Running the command on the system returns "2017-01-30"
> 
> Deploying my fact on a puppet node and running the puppet
> agent returns "Jan".
> 
> |
> $ puppet facts |grep lastrebootdate
> "lastrebootdate": "Jan",
> |
> 
> What did I miss?
> 
> Thank you,
> 
> Denny
> 
> -- 
> 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/1fe52550-e656-415a-9197-a692d397c8bc%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 puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/ccb700cd-6bf1-14dc-84cf-9b75d7181eca%40posteo.de.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-10 Thread Rob Nelson
At a guess, dollar signs inside double quotes interpolate, so it's 
extremely possible that somewhere earlier in the ruby run, $3 matched "Jan" 
somewhere and that was reused in your awk command. In the latter usage 
there's probably no $6 (that's a lot of matches!) or it amazingly has the 
value '$6'. I would definitely be more careful about escaping any dollars 
inside of double quoted strings that are passed to exec(), system(), or 
similar functions, as escaping that can be a nightmare when the stars align 
during your design but not weeks later during your usage.

On Tuesday, January 10, 2017 at 12:24:45 PM UTC-5, Denny wrote:
>
> Tried out another customfact "lastyumupdate" which looks like:
>
> Facter.add(:lastyumupdate) do
>   setcode do
> Facter::Util::Resolution.exec("yum history |grep -E '^.*(Update| 
> U).*$' |head -n 1 |awk '{print $6}'")
>   end
> end
>
> This one returns on command line "2017-01-10" AND sets the fact correct
>
> $ puppet facts |grep last
> "lastrebootdate": "Jan",
> "lastyumupdate": "2017-01-10",
>
>
> Any help is appreciated :)
>
>
> Denny
>
> Am Dienstag, 10. Januar 2017 17:47:36 UTC+1 schrieb Denny:
>>
>> PS: I'm running facter 3.5.0 with puppet 4.8.1 on CentOS 7
>>
>>
>> Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
>>>
>>> Hi there,
>>>
>>> probably a pretty easy to answer question.
>>>
>>> I want to try out adding custom facts. My first custom fact should be 
>>> "lastrebootdate"
>>>
>>> My code looks like this:
>>>
>>> Facter.add(:lastrebootdate) do
>>>   setcode do
>>> Facter::Util::Resolution.exec("/usr/bin/who -b |awk '{print $3}'")
>>>   end
>>> end
>>>
>>> Running the command on the system returns "2017-01-30"
>>>
>>> Deploying my fact on a puppet node and running the puppet agent returns 
>>> "Jan".
>>>
>>> $ puppet facts |grep lastrebootdate
>>> "lastrebootdate": "Jan",
>>>
>>> What did I miss?
>>>
>>> Thank you,
>>>
>>> Denny
>>>
>>

-- 
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/1fe52550-e656-415a-9197-a692d397c8bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-10 Thread Denny
Tried out another customfact "lastyumupdate" which looks like:

Facter.add(:lastyumupdate) do
  setcode do
Facter::Util::Resolution.exec("yum history |grep -E '^.*(Update| U).*$' 
|head -n 1 |awk '{print $6}'")
  end
end

This one returns on command line "2017-01-10" AND sets the fact correct

$ puppet facts |grep last
"lastrebootdate": "Jan",
"lastyumupdate": "2017-01-10",


Any help is appreciated :)


Denny

Am Dienstag, 10. Januar 2017 17:47:36 UTC+1 schrieb Denny:
>
> PS: I'm running facter 3.5.0 with puppet 4.8.1 on CentOS 7
>
>
> Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
>>
>> Hi there,
>>
>> probably a pretty easy to answer question.
>>
>> I want to try out adding custom facts. My first custom fact should be 
>> "lastrebootdate"
>>
>> My code looks like this:
>>
>> Facter.add(:lastrebootdate) do
>>   setcode do
>> Facter::Util::Resolution.exec("/usr/bin/who -b |awk '{print $3}'")
>>   end
>> end
>>
>> Running the command on the system returns "2017-01-30"
>>
>> Deploying my fact on a puppet node and running the puppet agent returns 
>> "Jan".
>>
>> $ puppet facts |grep lastrebootdate
>> "lastrebootdate": "Jan",
>>
>> What did I miss?
>>
>> Thank you,
>>
>> Denny
>>
>

-- 
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/e2a73c2c-af6f-42b1-a56c-13fd794f9349%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-10 Thread Denny
Tried out another customfact "lastyumupdate" which looks like:

Facter.add(:lastyumupdate) do
  setcode do
Facter::Util::Resolution.exec("yum history |grep -E '^.*(Update| U).*$' 
|head -n 1 |awk '{print↪$6}'")
  end
end

This one returns on command line "2017-01-10" AND sets the fact correct

$ puppet facts |grep last
"lastrebootdate": "Jan",
"lastyumupdate": "2017-01-10",


Any help is appreciated :)


Denny




Am Dienstag, 10. Januar 2017 17:47:36 UTC+1 schrieb Denny:
>
> PS: I'm running facter 3.5.0 with puppet 4.8.1 on CentOS 7
>
>
> Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
>>
>> Hi there,
>>
>> probably a pretty easy to answer question.
>>
>> I want to try out adding custom facts. My first custom fact should be 
>> "lastrebootdate"
>>
>> My code looks like this:
>>
>> Facter.add(:lastrebootdate) do
>>   setcode do
>> Facter::Util::Resolution.exec("/usr/bin/who -b |awk '{print $3}'")
>>   end
>> end
>>
>> Running the command on the system returns "2017-01-30"
>>
>> Deploying my fact on a puppet node and running the puppet agent returns 
>> "Jan".
>>
>> $ puppet facts |grep lastrebootdate
>> "lastrebootdate": "Jan",
>>
>> What did I miss?
>>
>> Thank you,
>>
>> Denny
>>
>

-- 
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/0ed5ff4f-634e-4b52-a1e8-bb6985b38aad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Re: writing custom fact -> return value not as expected

2017-01-10 Thread Denny
PS: I'm running facter 3.5.0 with puppet 4.8.1 on CentOS 7


Am Dienstag, 10. Januar 2017 17:44:23 UTC+1 schrieb Denny:
>
> Hi there,
>
> probably a pretty easy to answer question.
>
> I want to try out adding custom facts. My first custom fact should be 
> "lastrebootdate"
>
> My code looks like this:
>
> Facter.add(:lastrebootdate) do
>   setcode do
> Facter::Util::Resolution.exec("/usr/bin/who -b |awk '{print $3}'")
>   end
> end
>
> Running the command on the system returns "2017-01-30"
>
> Deploying my fact on a puppet node and running the puppet agent returns 
> "Jan".
>
> $ puppet facts |grep lastrebootdate
> "lastrebootdate": "Jan",
>
> What did I miss?
>
> Thank you,
>
> Denny
>

-- 
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/2e65ff6b-38c6-40cc-bc7e-2e0d107e32f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.