On Monday, January 13, 2014 7:02:29 PM UTC-6, alessandro mazzoli wrote:
>
> Hi all,
> I'm trying to automate the set up of the machines staging,passing by an
> php application ServerName , ProjectType,DbCredentials etc..(all strings)
> and convert to yaml
> Here's my common.yaml:
>
> ---
> users:
> -sn: server.example.com
> -project : Symfony
> -dbname : test
> -dbuser : test
> -dbpwd : test
> -sn: server2.example.com
> -project : Idephix
> -dbname : test
> -dbuser : test
> -dbpwd : test
>
> Here's my hiera.yaml
> ---
> :backends:
> -yaml
> :yaml:
> :datadir: '/etc/puppet/hieradata'
> :hierarchy:
> -common
>
>
> Is there any possibility on manifest to get all those variables by not
> specifing the index as below ??
> $users=hiera('users')
> $sn0=$users[*0*]['sn']
> $sn1=
> ......
> ...
>
> I would like to preserve all the configurations if possible inside
> common.yaml
>
>
I don't understand. If you didn't specify an index, then how would you
expect Puppet to know which sn you're talking about?
Your data are laid out quite strangely, however, probably not as you
intended. The value of the top-level 'users' key is an array of
one-element hashes, which are not all similar in apparent data content.
Perhaps this would be closer to what you want:
users:
-
sn: server.example.com
project : Symfony
dbname : test
dbuser : test
dbpwd : test
-
sn: server2.example.com
project : Idephix
dbname : test
dbuser : test
dbpwd : test
That makes 'users' an array containing only two elements, each one of them
a hash with five keys. You would still need to index into the array and
then into the hash, but all the data associated with a given server would
be in the same hash, accessed at the same array index.
Depending on how you want to use it, something like this might also be
useful:
users:
server.example.com:
project : Symfony
dbname : test
dbuser : test
dbpwd : test
server2.example.com:
project : Idephix
dbname : test
dbuser : test
dbpwd : test
That makes 'users' a hash of hashes, with server names as the outer hash
keys. You would access leaf elements like so:
$users = hiera('users')
$project = $users['server.example.com']['project']
If you don't want to rely on prior knowledge of the outer hash keys (i.e.
the server names) then you can extract them from the data via the keys()
function, available from Puppetlabs's "stdlib" add-in module
(https://forge.puppetlabs.com/puppetlabs/stdlib).
John
--
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/133448a8-aa61-451c-8856-aba80c4a10d2%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.