Getting the location of the manifest file

25 views
Skip to first unread message

Go Iwai

unread,
Aug 15, 2021, 9:18:54 PMAug 15
to puppet...@googlegroups.com
Hello,

I want to know the location where puppet-apply locally applied the
manifest file.

$ pwd
/path/to/manifests
$ puppet apply file.pp

In this case above, can I anyhow get the location of
/path/to/manifests/file.pp within file.pp?

Kind regards,
Go

Martin Alfke

unread,
Aug 16, 2021, 6:53:37 AMAug 16
to puppet...@googlegroups.com
Hi Go,

what do you want to achieve?
When using puppet apply, a manifest can be anywhere on the filesystem.

Best,
Martin
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/CAAyfkv-2dC--QR_1tz1ux%2BrgYaVsqjseB4oTEZ-EnkZPNXnn1w%40mail.gmail.com.

Ben Ford

unread,
Aug 16, 2021, 12:10:48 PMAug 16
to puppet...@googlegroups.com
Hi Go!

I'm not sure what you're trying to accomplish, but you'd probably be better off locating your code in a module on your modulepath and then Puppet takes care of all the relative paths for you. https://puppet.com/docs/puppet/latest/modules_fundamentals.html

Go Iwai

unread,
Aug 16, 2021, 10:34:00 PMAug 16
to puppet...@googlegroups.com
Hello Martin,

Let's say we have three directories:

preproduction/ preproduction/ private/

There are different manifest files saved in the same name, like
service-deploy.pp.

In the manifest service-deploy.pp, I want to get the absolute path to
itself, then determine the variable of env like:

$dir = dirname($file) # $file is absolute path to service-deploy.pp
like: '/path/to/manifests/preproduction/service-deploy.pp'
$env = split($dir, '/')[-1]

Then, hiera dynamically maps the correspond yaml file under the $env like:

mapped_paths: [services, svc, "environments/%{env}/%{svc}.yaml"]

This is what I want to realise. I know puppet has already provided a
switch in response to $environment, e.g.,
/etc/puppetlabs/code/environments/production. In this way, I have to
maintain some branches in parallel. That is what I don't want to do.

Kind regards,
Go
> To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/2E04526A-7F74-4F84-99E4-4C1D675FC67C%40gmail.com.

Ben Ford

unread,
Aug 17, 2021, 1:25:19 PMAug 17
to puppet...@googlegroups.com
Hiera provides an environment hierarchy. Is that what you're looking for? https://puppet.com/docs/puppet/latest/hiera_config_yaml_5.html

Go Iwai

unread,
Aug 27, 2021, 2:38:52 AMAug 27
to Puppet Users
Hello Ben,

On Wednesday, August 18, 2021 at 2:25:19 AM UTC+9 Ben Ford wrote:
Hiera provides an environment hierarchy. Is that what you're looking for? https://puppet.com/docs/puppet/latest/hiera_config_yaml_5.html

No, it is not. I know that the environmental hierarchy provided by hiera realise what I want to do but I don't want to do with that.

Let me restate the question. How can we get the absolute path of the manifest file in itself?

% pwd
/xxx/yyy
% puppet apply ../zzz/manifest.pp

In this example above, I would get the /xxx/zzz/manifest.pp in the manifest somehow.

Kind regards,
Go
 
Reply all
Reply to author
Forward
0 new messages