Hiera and nested / reuse variables

62 views
Skip to first unread message

Helmut Schneider

unread,
Jun 21, 2018, 12:35:23 PM6/21/18
to puppet...@googlegroups.com
Hi,

common.yaml:

profiles:
mailserver:
postfix:
instances:
postfix-in:
instance_path: '/etc/postfix-in'
other_path: "%{instance_path}" <= required

Is it possible to nest both variables somehow? Or alternatively from
common.pp:

$instance_path =
$profiles['mailserver']['postfix']['instances'][postfix-in]['instance_pa
th']

Can I somehow use $instance_path from common.pp in common.yaml?

helmut@puppet:~$ sudo puppet agent -V
4.10.12
helmut@puppet:~$

Thank you!

Angel L. Mateo

unread,
Jun 22, 2018, 6:04:15 AM6/22/18
to puppet...@googlegroups.com
El 21/06/18 a las 14:32, Helmut Schneider escribió:
> Hi,
>
> common.yaml:
>
> profiles:
> mailserver:
> postfix:
> instances:
> postfix-in:
> instance_path: '/etc/postfix-in'
> other_path: "%{instance_path}" <= required
>
> Is it possible to nest both variables somehow? Or alternatively from
> common.pp:

common.yaml:

instance_path: '/etc/postfix-in'
profile:
mailserver:
postfix:
instances:
postfix-in:
instance_path: "%{hiera('instance_path')}"
other_path: "%{hiera('instance_path')}"

or, if you want to reuse value in the same file:

instance_path: &instance_path '/etc/postfix-in'
other_path: *instance_path

>
> Can I somehow use $instance_path from common.pp in common.yaml?
>
I don't think so. hiera is processed before catalog compilation.

--
Angel L. Mateo Martínez
Sección de Telemática
Área de Tecnologías de la Información
y las Comunicaciones Aplicadas (ATICA)
http://www.um.es/atica
Tfo: 868889150
Fax: 868888337

Helmut Schneider

unread,
Jul 13, 2018, 2:10:19 PM7/13/18
to puppet...@googlegroups.com
Angel L. Mateo wrote:

> El 21/06/18 a las 14:32, Helmut Schneider escribió:
> > Hi,
> >
> > common.yaml:
> >
> > profiles:
> > mailserver:
> > postfix:
> > instances:
> > postfix-in:
> > instance_path: '/etc/postfix-in'
> > other_path: "%{instance_path}" <= required
> >
> > Is it possible to nest both variables somehow? Or alternatively from
> > common.pp:
>
> common.yaml:
>
> instance_path: '/etc/postfix-in'
> profile:
> mailserver:
> postfix:
> instances:
> postfix-in:
> instance_path: "%{hiera('instance_path')}"
> other_path: "%{hiera('instance_path')}"
>

I tried

profile:
mailserver:
postfix:
instances:
postfix-in:
instance_path: '/etc/posfix-in'
other_path:
"%{hiera('profile::mailserver::postifx::instances::postfix-in::instance_
path')}"

which gives an empty value.

> or, if you want to reuse value in the same file:
>
> instance_path: &instance_path '/etc/postfix-in'
> other_path: *instance_path

This works but can I also construct a string here? Like

instance_path: &instance_path '/etc/postfix-in'
other_path: "*instance_path something_else"

Reply all
Reply to author
Forward
0 new messages