manip of a hash

6 views
Skip to first unread message

Albert Shih

unread,
May 23, 2016, 11:17:23 AM5/23/16
to puppet...@googlegroups.com
Hi,

I'm running puppet 3.8.x

I try to do something like


hieradata/myhost.yaml

my_apache::vhosts:
'my_new_vhost':
name:
port:
ssl:
etc..

modules/my_apache/manifests/init.pp

class my_apache($vhosts = {}) {
validate_hash($vhosts)
$hiera_vhosts = hiera_hash("${module_name}::vhosts", undef)
include 'apache'
create_resources('apache::vhost', $hiera_vhosts)
}

and it's working.

Now I would like to add

ssl_cert and ssl_key inside the configuration of apache_vhost.

The point is I have two other variables inside

hieradata/OS.yaml
hieradata/common.yaml

like

ssl_pub_key
ssl_priv_key

who are the default place of the cert files

So I cannot put something

my_apache::vhosts:
'my_new_vhost':
name:
port:
ssl: true
ssl_cert: $ssl_pub_key
ssl_key: $ssl_priv_key

I don't want to put the real information because that's mean I duplicate
the information.

I still want the ssl_pub_key/ssl_priv_key inside my hieradata/common.yaml
because those variables are use in other module.

So the only way I see it is to put inside my

modules/my_apache/manifests/init.pp

something like

class my_apache($vhosts = {}) {
$ssl_pub_key= hiera('ssl_pub_key')
$ssl_priv_key=hiera('ssl_priv_key')

validate_hash($vhosts)
$hiera_vhosts = hiera_hash("${module_name}::vhosts", undef)
include 'apache'
create_resources('apache::vhost', $hiera_vhosts)
}

but I don't see how I can put those two informations inside the
hiera_vhosts values.

Regards.







--
Albert SHIH
DIO bâtiment 15
Observatoire de Paris
5 Place Jules Janssen
92195 Meudon Cedex
France
Téléphone : +33 1 45 07 76 26/+33 6 86 69 95 71
xmpp: j...@obspm.fr
Heure local/Local time:
lun 23 mai 2016 17:04:46 CEST

Andreas Zuber

unread,
May 23, 2016, 11:38:27 AM5/23/16
to puppet...@googlegroups.com
Hi

You can just use variable interpolation: https://docs.puppet.com/hiera/1/variables.html .This will basically makes another hiera lookup to retrieve the value of ssl_pub_key and ssl_priv_key.

hieradata/myhost.yaml
my_apache::vhosts:
    'my_new_vhost':
        name:
        port:
        ssl_pub_key: "%{hiera('ssl_pub_key')}"
        ssl_priv_key: "%{hiera('ssl_priv_key')}"

hieradata/common.yaml

ssl_pub_key: 'some pub key..'
ssl_priv_key: 'some priv key'

Additionally there are also tools available to manage keys outside of your yaml files you you don't have to check them into your version control: https://github.com/duritong/trocla

Greetings
Andreas
Reply all
Reply to author
Forward
0 new messages