1

I'm using puppet 4.10.9 with facter 3.6.8. I have a question(s) regarding the use of facts in a manifest that I'll ask in a simple form, and a more complex form. First, the simple question.

On an agent I can see the following addresses:

facter --show-legacy | grep ipaddress
ipaddress => 192.168.25.75
ipaddress_enp0s3 => 10.0.2.15
ipaddress_enp0s8.25 => 192.168.25.75
ipaddress_lo => 127.0.0.1

I want to use 'ipaddress_enp0s8.25' (a vlan interface) in a manifest. Yes, I realize I could use 'ipaddress' but for reasons I'll explain later I would like to use the vlan interface specifically.

When I try to use this interface reference in a manifest I get a Syntax error:

   listenip => $ipaddress_enp0s8.25

These references DO WORK, but again, I want to use the vlan interface specifically:

   listenip => $ipaddress

   listenip => $networking['ip']

So how can I use 'ipaddress_enp0s8.25' ?

Here's the more complex angle, and some background. This is part of a larger project that involves recycling (spin up, terminate) the same environment frequently. There's been careful attention to how nodes behave as they do initial provisioning. One of the first issues I noted was:

'Evaluation Error: Operator '[]' is not applicable to an Undef Value.' 

Because at that time I was trying to use:

$networking['interfaces']['enp0s8.25']['ip']

And this doesn't exist at the initial run. I could not get past 'Loading facts'

So I settled for '$networking['ip']' which works fine. However at first run, this returns 10.0.2.15. At subsequent runs it returns the desired address 192.168.25.75. The result is, generally an operational node, but a 30 minute lapse for certain services.

What can I use here so that the desired vlan address becomes the value? I'd like to try 'ipaddress_enp0s8.25' but I cannot for reasons noted above.

A couple of misc. items to note:

  • I am creating that vlan interface using razorsedge-network module.
  • I was able to use 'ipaddress_enp0s8_25' without issue in puppet 3.8
1

Accessing facts has changed in version 4. Try accessing the fact via the $facts hash, $facts['ipaddress_enp0s8.25'], instead of using a top scope variable.

You can still use top scope variables to access facts, but they have been deprecated and you should move over to using the $facts hash as soon as possible.

In this case, it appears that this fact has changed names and this is the problem you are running into. In the previous version, the facter name was escaped with underscores, while the newer version has periods, which cannot be escaped (as far as I know) when accessing the fact using a top-scope variable, hence the necessity to use the $facts hash.

$ipaddress_enp0s8.25 will get interpolated incorrectly, as the period would need to be escaped.

$facts['ipaddress_enp0s8.25'] will not get interpolated as we're accessing the element of the hash with single quotes.

Read more about how facts are used in Puppet 4 here:

https://puppet.com/docs/puppet/4.10/lang_facts_and_builtin_vars.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.