thanks for the clarification. It's fixed by creating JSON format data and
using parsejson.

Thanks!

- Allen

On Tue, May 5, 2015 at 11:45 PM, Michael Pawlak <[email protected]> wrote:

>   Allen,
>
> The generate function simply returns the output of an external command, as
> executed on the puppet master.
>
> Since bash only started supporting associative arrays
> (hashes/dictionaries) in version 4 it is highly likely that your bash
> script is outputting a string and not a hash. The format for an associative
> array in bash also doesn't resemble the same syntax that you find in puppet
> (ruby).
>
> I'm not sure as to how ruby or puppet for that matter would interpret
> bash's representation of an array or hash. Bash has limited ability to
> define data structures. This in turn would limit how an interpreter such as
> ruby or puppet could effectively use its data types.
>
> With this being said, try possibly using ruby or python for your external
> program language. This way the data structure will be in s more usable
> format. If that's not possible, research associative arrays in bash and see
> if you can make them work with puppet.
>
> Mike
>
> Sent with AquaMail for Android
> http://www.aqua-mail.com
>
> On May 5, 2015 5:25:08 PM Allen Myers <[email protected]> wrote:
>
>> definitely helps! that's the road I was just researching, but it helps to
>> verify that I'm on the right track. :)
>>
>> Thanks!
>>
>> - Allen
>>
>> On Tuesday, May 5, 2015 at 5:06:15 PM UTC-7, Allen Myers wrote:
>>>
>>> Hi,
>>>
>>> I have shell script that generates a hash of user accounts that need to
>>> be created/maintained
>>> by puppet. In my manifest I'm calling it using the generate() function:
>>>
>>> $myusers = generate ('/bin/sh', '-c', '/path/to/my/script.sh')
>>>
>>> The output of the script looks like:
>>>
>>>                 { 'user1' => {  name => 'user1',  ensure => present,
>>>  gid => xxxx,  home => '/home/user1',  managehome => true,  purge_ssh_keys
>>> => true,  shell => '/bin/bash',}, 'user2' => {  name => 'user2',  ensure =>
>>> present,  gid => xxxx,  home => '/home/user2',  managehome => true,
>>>  purge_ssh_keys => true,  shell => '/bin/bash',},}
>>>
>>> then I call create_resources as
>>>
>>>                 create_resources (user, $myusers)
>>>
>>> and when I run 'puppet agent --test' on the client I get
>>>
>>>                 Error: Could not retrieve catalog from remote server:
>>> Error 400 on SERVER: create_resources(): second argument must be a hash at
>>> /etc/puppet/environments/mgmt/manifests/01-all-nodes.pp:38 on node server1
>>>
>>> If I comment out the create_resources and add the line
>>>
>>>                    validate_hash ($myusers)
>>>
>>> then it fails with
>>>
>>>                  Error: Could not retrieve catalog from remote server:
>>> Error 400 on SERVER: "{ 'user1' => {  name => 'user1',  ensure => present,
>>>  gid => xxxx,  home => '/home/user1',  managehome => true,  purge_ssh_keys
>>> => true,  shell => '/bin/bash',}, 'user2' => {  name => 'user2',  ensure =>
>>> present,  gid => xxxx,  home => '/home/user2',  managehome => true,
>>>  purge_ssh_keys => true,  shell => '/bin/bash',},}" is not a Hash.  It
>>> looks to be a String at
>>> /etc/puppet/environments/mgmt/manifests/01-all-nodes.pp:38 on node server1
>>>
>>> Yet, if I take the output of the script and just put it directly into
>>> the manifest, it works fine; ie,
>>>
>>>                  $myusers = { 'user1' => {  name => 'user1',  ensure =>
>>> present,  gid => xxxx,  home => '/home/user1',  managehome => true,
>>>  purge_ssh_keys => true,  shell => '/bin/bash',}, 'user2' => {  name =>
>>> 'user2',  ensure => present,  gid => xxxx,  home => '/home/user2',
>>>  managehome => true,  purge_ssh_keys => true,  shell => '/bin/bash',},}
>>>                  create_resources (user, $myusers)
>>>
>>> and it works.
>>>
>>> So, based on the error messages, it's obvious that the generate()
>>> function is returning the string data type. Can I force it to return the
>>> hash data type?
>>> Or is there a way to convert a string to a hash?
>>>
>>> Thanks!
>>>
>>> - Allen
>>>
>>  --
>> 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/91e35347-0765-491c-95de-ea31f0eaceb6%40googlegroups.com
>> <https://groups.google.com/d/msgid/puppet-users/91e35347-0765-491c-95de-ea31f0eaceb6%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>


-- 

- Allen

-- 
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/CAET%2B4WN2-a%2BT28z2sO2diJrBL4wPWB3KJQVC55_rVwHuA_BQSw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to