using custom array based fact with defined type

420 views
Skip to first unread message

Ritesh Nanda

unread,
Apr 21, 2014, 7:27:21 PM4/21/14
to puppet...@googlegroups.com
Hello , 

I have a custom facts which returns the block devices based on some condition in an array.

 facter | grep arraydev
arraydev => ["sdb", "sdc"]

Now i want to use this array in defined type so that a exec resource can run as no. of times elements in the array.

vi modules/test/manifest/exeecho.pp

define test::exeecho() {
        exec {"echo_${name}":
          command => "echo hello >> /tmp/foo23",
          path => ['/bin'],
         }
       }


vi modules/test/manifest/init.pp

class test {
test::exeecho{$::arraydev:}
}


But puppet agent -t run gives a error.

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type exec at /etc/puppetlabs/puppet/modules/test/manifests/exeecho.pp:5 on node pzxdcc0002.cdbt.pldc.kp.org
Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run

Please tell me if i am doing something wrong.

Regards,
Ritesh Nanda






Antoine Cotten

unread,
Apr 22, 2014, 9:07:41 AM4/22/14
to puppet...@googlegroups.com
Could you please post the result of: validate_array($::arraydev) ?

You need to have the "puppetlabs/stdlib" module installed

Toni

jcbollinger

unread,
Apr 22, 2014, 9:15:03 AM4/22/14
to puppet...@googlegroups.com


Your manifests look fine to me, but the error message you report is surpassingly strange.  The exec resource type is distributed with Puppet itself, so the parser is exceedingly confused when it claims not to recognize it.  I am inclined to suspect that the Puppet installation on your master is borked.  Perhaps you have two different versions installed at the same time, such as maybe one from an RPM and another from a gem?


John

Ritesh Nanda

unread,
Apr 22, 2014, 2:10:46 PM4/22/14
to puppet...@googlegroups.com
Hello Toni , John

Thanks for your help.

Doing validate array gives a  

 Error 400 on SERVER: "" is not an Array.  It looks to be a String

I made it working using  $arrayvar = split($::arraydev, '[,]') then calling  test::exeecho{$arrayvar:} , in this way it works and its process the array . 

now the init.pp looks like 

class test {
$arrayvar = split($::arraydev, '[,]')
test::exeecho{$arrayvar:}
}

Doing validate array tells me it is string not an array , Is this the right way to do it. Or there can be a better way to do it.

Regards,
Ritesh Nanda

José Luis Ledesma

unread,
Apr 22, 2014, 3:47:20 PM4/22/14
to puppet...@googlegroups.com

Facter doesn't support arrays, only strings until v2.0, so the only way I know if what you did, although I usually use this form:

Anyfact => value1,value2,value3

And then just split with the ,

Regards,

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/5f7536a9-a42e-4f1d-b1fe-1b4bda324f51%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ritesh Nanda

unread,
Apr 22, 2014, 7:21:51 PM4/22/14
to puppet...@googlegroups.com
Thanks Jose


--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/iecmekCfTVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAF_B3dfYknba5PdRhd%3Dv0ObPbxKK76898KaWZor1XooUxPOpyw%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.



--

 With Regards 

 Ritesh Nanda




Antoine Cotten

unread,
Apr 23, 2014, 11:20:05 AM4/23/14
to puppet...@googlegroups.com
Actually Facter does support arrays since v2.0.1, Ritesh did not mention which version he was using.

Ritesh if you use Facter 2.0.1 I recommend you to make sure your fact is an actual Structured Fact, like described in this documentation page: Facter 2.0: Overview of Custom Facts With Examples
I suspect you're trying to build an array from Strings using a funny construction, like concatenate "[" and "]" to your data, am I right? This is indeed how you define it in Puppet DSL, but in Ruby (and Facter) this would still be recognized as a string.

Ritesh Nanda

unread,
Apr 23, 2014, 12:00:57 PM4/23/14
to puppet...@googlegroups.com
Hello toni,

Yes , you are correct , i didn't knew about array not been supported in facter previous version . I am using 1.7.3 version.
thanks for pointing me out to the link , i will update facter and try to do in structured fashion.

Regards,
Ritesh


--
You received this message because you are subscribed to a topic in the Google Groups "Puppet Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/puppet-users/iecmekCfTVg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/d858d064-bceb-421d-8db3-9bf75bf4f186%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages