Yes, you can put multiple key=value pairs in a single file. Puppet v4
supports three known types:
1. YAML (must end in .yaml)
2. JSON (must end in .json)
3. Text (must end in .txt)
When working with .txt files you can only define string values. Arrays and
hashes are not supported. Also. If your file is a program or script it must
be executable (execute bit set). The script itself must output key=value.
So what is required is the:
echo "my_fact=my_value"
This would create the fact call "my_fact" and it would set the value of it
to "my_value". I don't mess around with external facts to much so I'm not
100% positive if you can perform the evaluation in the fact declaration,
but my assumption is you can. What is required is that the key=value
statement is echo'd to the stdout and that what is echo'd to stdout is the
literal fact name equal to the literal value. As long as bash performs its
operations properly then the literal values would be output, not the
expression. Puppet then will pickup the stdout stream and set the fact
accordingly. Again, this all an educated guess. Probably should have tested
it myself, but I'll let that to you. :)
Hope that helps,
Joshua Schaeffer
P.S.
Executable facts on Windows should be known extension types as well and can
include:
- .com or .exe
- .psl (PowerShell)
- .cmd or .bat (batch script)
On Wednesday, March 22, 2017 at 5:49:53 PM UTC-6, Warron French wrote:
>
> Thanks Rob. I will try both approaches; for me there is more appeal in
> simply using a shell script.
>
> Peter, can I generate multiple key=value pairs inside the same shell
> script? I don't explicitly have to do it the way you presented with
>
> key="key_name"
> value="evaluated_expression"
>
> echo "${key}=${value}" Do I?
>
> Can I simple skip the key="key_name" part and just do the
> expression_evaluation assigned to a variable and then echo them together?
>
> Perhaps I can write shell functions and execute them all?
>
> --------------------------
> Warron French
>
>
> On Wed, Mar 22, 2017 at 7:35 PM, Rob Nelson <[email protected]
> <javascript:>> wrote:
>
>> That's probably one of the best ways to do this. But...
>>
>> You CAN use double quotes around a string. You will need to escape
>> characters that will otherwise be interpolated like double quotes and
>> dollar signs. I'm going off memory but I think `"awk '{print \$1_\$2}'"`
>> should interpolate to `awk '{print $1_$2}'` properly. This is often tedious
>> and may require some trial and error to ensure both the double quotes and
>> the system call that uses it don't interpolate too much but it can work.
>>
>> On Wed, Mar 22, 2017 at 7:07 PM Peter Bukowinski <[email protected]
>> <javascript:>> wrote:
>>
>>> Hi Warron,
>>>
>>> I'd consider using an external, executable fact to avoid ruby altogether.
>>>
>>>
>>> https://docs.puppet.com/facter/3.6/custom_facts.html#executable-facts-----unix
>>>
>>> Basically, you can write a bash script (or use any language you want),
>>> drop it into '<MODULEPATH>/<MODULE>/facts.d/' on your puppet server,
>>> and it will be synced to all your nodes (assuming you use pluginsync).
>>>
>>> The only requirement for executable fact scripts is that they must
>>> return key/value pairs in the format 'key=value'. Multiple keys/values
>>> get their own line. In your case, you could do something like this:
>>>
>>> -----
>>> #!/bin/bash
>>>
>>> key="qty_monitors_total"
>>> value=$(your parsing command for /var/log/Xorg.0.log here)
>>>
>>> echo "${key}=${value}"
>>> -----
>>>
>>> Save the file as an executable script in the above mentioned path and
>>> it should be available on the next puppet run.
>>>
>>> On Wed, Mar 22, 2017 at 3:24 PM, warron.french <[email protected]
>>> <javascript:>> wrote:
>>> > Hello, I have finally learned how to write a Custom Fact; and
>>> duplicated the
>>> > syntax several times over inside the same .rb file.
>>> >
>>> > I am using syntax that looks like the following:
>>> >
>>> > Facter.add('qty_monitors_total') do
>>> > setcode do
>>> > Facter::Util::Resolution.exec('/bin/grep " connected"
>>> > /var/log/Xorg.0.log | cut -d\) -f2,3,4 | grep GPU |sort -u | wc -l')
>>> > end
>>> > end
>>> >
>>> > I don't know of any other way to do this yet; but that's not my
>>> concern yet.
>>> >
>>> > What I would like to know is how can I use an awk command within the
>>> > Facter::Util::Resolution.exec('.........') line.
>>> >
>>> > I have a need to essentially reproduce the line above but drop wc -l
>>> and
>>> > add awk '{ print $2"_"$3"_on_"$1$4 }'
>>> >
>>> > I need the awk command to pretty much look like this; the problem is
>>> awk
>>> > uses its own single quotes (') and it will break the ruby code.
>>> >
>>> > I am not a ruby developer; so if someone could either tell me:
>>> >
>>> > It's just not possible; or
>>> > do it this way
>>> >
>>> >
>>> > That would be greatly appreciated. Thank you,
>>> >
>>> > --------------------------
>>> > Warron French
>>> >
>>> > --
>>> > 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] <javascript:>.
>>> > To view this discussion on the web visit
>>> >
>>> https://groups.google.com/d/msgid/puppet-users/CAJdJdQmZXQAd%2Bo%2Bnp-NHqxGHnXubf%2Bac-dP5FPoy4QYMEVuBuA%40mail.gmail.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] <javascript:>.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/puppet-users/CAJA1CN9aFH4Eza-FoxzrfXDWiGCUHXE%2BGFt2Nu%3DjK2eDzV4upg%40mail.gmail.com
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
>> Rob Nelson
>>
>> --
>> 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] <javascript:>.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/puppet-users/CAC76iT8Sduj%2BL%3DR3hZfSqkqeUgp9eBsQLjuBWEMrW6L1xxpE0Q%40mail.gmail.com
>>
>> <https://groups.google.com/d/msgid/puppet-users/CAC76iT8Sduj%2BL%3DR3hZfSqkqeUgp9eBsQLjuBWEMrW6L1xxpE0Q%40mail.gmail.com?utm_medium=email&utm_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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-users/e3da79a8-61ac-4ca8-9adc-118b96692b48%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.