Ask Your Question
0

Question on custom fact

asked 2016-03-11 18:56:43 -0500

ancymathews gravatar image

updated 2016-03-11 23:43:10 -0500

Hi, I am trying to get my first custom fact working.

My custom fact executes a shell script to get the value and returns a string. Code is :

Facter.add(':ora_psu_num') do
setcode do
        Facter::Core::Execution.exec('/oraback01/sw/scripts/get_oracle_psu_num.ksh')
end
end

To test it I set env variable $FACTERLIB to include my custom facter code and query

facter :ora_psu_num

and I get the expected result

17478514,18031668,18522509,19121551,19769489,20299013,20760982,21352635,21948347

However, When I try to get it from puppet code it is not returning any value:

Code is:

$foo=$::ora_psu_num
notify {"$foo":}

Error:

puppet apply test_facter.pp
Could not retrieve fact='package_provider', resolution='<anonymous>': Malformed version number string 3.7.4 (Puppet Enterprise 3.7.2)
Notice: Compiled catalog for uora1008n.bsc.bscal.com in environment production in 0.02 seconds
Notice:
Notice: /Stage[main]/Main/Notify[]/message: defined 'message' as ''
Notice: Finished catalog run in 0.11 seconds
Error: Failed to apply catalog: No title provided and "Notify[]" is not a valid resource reference

What am I doing wrong? Advice.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-03-11 19:36:59 -0500

ancymathews gravatar image

updated 2016-03-11 23:43:29 -0500

I figured it out.

Modified the code from

Facter.add(':ora_psu_num' )do

to

Facter.add(:ora_psu_num )do

and everything worked as expected.

edit flag offensive delete link more

Comments

Nice catch. In ruby, a name prefixed with ":" is a symbol, and in your earlier example, you created a fact with the string ":ora_psu_num" looking up "facter :ora_psu_num" found the fact (with the : as a part of the key) Good luck, happy factoring! Hard to find good help on custom facts!

DarylW gravatar imageDarylW ( 2016-03-13 23:35:35 -0500 )edit

Thank you for the explanation, It makes sense now.

ancymathews gravatar imageancymathews ( 2016-03-14 00:45:51 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-03-11 18:56:43 -0500

Seen: 163 times

Last updated: Mar 11 '16