How to store "bash command:" output in a variable as array

2,100 views
Skip to first unread message

sasikiran v

unread,
Nov 25, 2013, 3:54:18 AM11/25/13
to puppet...@googlegroups.com
exec {'ls':
       command => "ls",
       path => "/usr/bin:/bin",
       provider => shell,
}

So the output of "ls" contains files/directories, these should be stored in a array for suppose "$my_array" and it should be used globally in the module.

Can any one help me in  this

Johan De Wit

unread,
Nov 25, 2013, 4:38:28 AM11/25/13
to puppet...@googlegroups.com
Hi,

You should have a look at 'facts'.

An exec is executed in the last phase of a puppet run. If you need
information form a node, that you need in eg. templates, modules etc,
you will have to use facts.

Have a look at the last image on http://puppetlabs.com/puppet/what-is-puppet

Writing simple custom facts is not that difficult.
http://docs.puppetlabs.com/guides/custom_facts.html

hth

Grts

jo
> --
> 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/b53e7979-7d5c-40a1-8110-731ab0f45179%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.


--
Johan De Wit

Open Source Consultant

Red Hat Certified Engineer (805008667232363)
Puppet Certified Professional 2013 (PCP0000006)
_________________________________________________________

Open-Future Phone +32 (0)2/255 70 70
Zavelstraat 72 Fax +32 (0)2/255 70 71
3071 KORTENBERG Mobile +32 (0)474/42 40 73
BELGIUM http://www.open-future.be
_________________________________________________________


Next Events:
Puppet Advanced Training | https://www.open-future.be/puppet-advanced-training-12-till-14th-november
Zabbix Certified Training | http://www.open-future.be/zabbix-certified-training-18-till-20th-november
Zabbix Large Environments Training | http://www.open-future.be/zabbix-large-environments-training-21-till-22nd-november
Puppet Fundamentals Training | http://www.open-future.be/puppet-fundamentals-training-10-till-12th-december
Subscribe to our newsletter | http://eepurl.com/BUG8H

Štěpán Cenek

unread,
Nov 25, 2013, 7:22:36 AM11/25/13
to puppet...@googlegroups.com
Hi y'all,
creating custom fact is great. If you need it just for testing, use generate.

$arr = generate('/bin/ls')

Btw: the difference between exec and generate is that generate is executed right on the beginning of Puppet run (so it will fail if it's using tool installed later by Puppet). You will get only exit code from exec, not the output.

--
Stepan Cenek
System Engineer
GoodData |


Dne pondělí, 25. listopadu 2013 10:38:28 UTC+1 Johan De Wit napsal(a):

Paul Tötterman

unread,
Nov 25, 2013, 10:03:41 AM11/25/13
to puppet...@googlegroups.com
Btw: the difference between exec and generate is that generate is executed right on the beginning of Puppet run

No. The difference is that generate() is run on the master and exec on the agent: http://docs.puppetlabs.com/references/latest/function.html#generate

Cheers,
Paul

Stepan Cenek

unread,
Nov 25, 2013, 10:13:16 AM11/25/13
to puppet...@googlegroups.com
Sorry for confusion, I'm used to masterless Puppet...
> --
> 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/mnrRLQHTnMs/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/3d8c7c6c-fbef-45c3-a30b-594ab5b73be1%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages