Re: [Puppet Users] Newbie question about fetching specific value of a key from hash

2016-02-04 Thread Martin Alfke
Hi Sam
On 03 Feb 2016, at 16:28, Sam  wrote:

> My hiera entries -
> 
> mysqlconfig::custom_mysql_options:
>   mysqld:
> replicate-ignore-db: 'test'
> server-id: 12
> datadir: '/data/mysql_data'
> 
> 
> I want to get the value of datadir in my puppet module. Please let me know 
> what is the syntax I need to use to fetch this value. I tried something as 
> follows but it doesn't work. 
> 
> 
> $datadir = hiera('mysqlconfig::custom_mysql_options[datadir]’)

With hiera you can only specify keys, not elements of a hash.

you should change this to:

$custom_mysql_options = hiera(‘mysqlconfig::custom_mysql_options’)

You can now set a new variable reading the hash element:

$datadir = $custom_mysql_options[‘datadir’]

> 
>   file { "$datadir":
> ensure => directory,
> owner  => 'mysql',
> group  => 'mysql',
> mode   => '0755',
>   }
> 
> 
hth,
Martin

> Thanks in advance
> Sam
> 
> -- 
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/puppet-users/95efaffa-4873-4fda-9caa-3a38e7b3c1de%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/7687C384-3106-4A61-AC14-1F90BB21CB33%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Puppet Users] Newbie question about fetching specific value of a key from hash

2016-02-04 Thread Craig Dunn
>> I want to get the value of datadir in my puppet module. Please let me know 
>> what is the syntax I need to use to fetch this value. I tried something as 
>> follows but it doesn't work.
>>
>>
>> $datadir = hiera('mysqlconfig::custom_mysql_options[datadir]’)
>
> With hiera you can only specify keys, not elements of a hash.

That's not the case with Hiera 2.0+ which supports drilling down into
hashes and arrays... so you should also be able to do

$datadir = hiera('mysqlconfig::custom_mysql_options.datadir')

If you're still on Hiera 1.0 though, what Martin said.

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CACxdKhEjxb1sLXugQD5dTHBYbxLcvrATC1jjZhwcXKWvvXAMSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[Puppet Users] Newbie question about fetching specific value of a key from hash

2016-02-03 Thread Sam
My hiera entries -

mysqlconfig::custom_mysql_options:
  mysqld:
replicate-ignore-db: 'test'
server-id: 12
datadir: '/data/mysql_data'


I want to get the value of datadir in my puppet module. Please let me know 
what is the syntax I need to use to fetch this value. I tried something as 
follows but it doesn't work. 


$datadir = hiera('mysqlconfig::custom_mysql_options[datadir]')

  file { "$datadir":
ensure => directory,
owner  => 'mysql',
group  => 'mysql',
mode   => '0755',
  }


Thanks in advance
Sam

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/95efaffa-4873-4fda-9caa-3a38e7b3c1de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.