voxpupuli / puppet-network

Types and providers to manage network interfaces
https://forge.puppet.com/puppet/network
Apache License 2.0
66 stars 108 forks source link

our custom facts fail, when they could instead just use facter! #198

Open igalic opened 7 years ago

igalic commented 7 years ago

Affected Puppet, Ruby, OS and module versions/distributions

How to reproduce (e.g Puppet code you use)

puppet facts

What are you seeing

Error: Facter: error while resolving custom fact "network_primary_interface": undefined method `split' for nil:NilClass
Error: Facter: error while resolving custom fact "network_primary_ip": undefined method `split' for nil:NilClass

What behaviour did you expect instead

We should defer to facter3, instead of trying to figure all of this out on our own.

rski commented 7 years ago

fixed by this (in theory): https://github.com/voxpupuli/puppet-network/pull/200

igalic commented 7 years ago

i'll update my production servers with this, and see how they blow up

igalic commented 7 years ago

they don't.


however, it doesn't work via facter -p, only via puppet facts

rski commented 7 years ago

I'm not sure if i got what happens. If i got this right:

igalic commented 7 years ago

could this be an ordering issue?

rski commented 7 years ago

don't think so. I don't think I understand what the issue is, that's why i'm asknig what the output of the commands is.

igalic commented 7 years ago
igalic@app02 ~> sudo -H /opt/puppetlabs/puppet/bin/puppet facts | jq .values.networking.primary
"eth0"
igalic@app02 ~> sudo -H /opt/puppetlabs/puppet/bin/puppet facts | jq .values.network_primary_interface
"eth0"
igalic@app02 ~> sudo -H /opt/puppetlabs/puppet/bin/facter -p networking.primary
eth0
igalic@app02 ~> sudo -H /opt/puppetlabs/puppet/bin/facter -p network_primary_interface

igalic@app02 ~> 
rski commented 7 years ago

now that is interesting

rski commented 7 years ago

can you post the output of facter -p networking as a whole?

igalic commented 7 years ago
{
  domain => "esat",
  fqdn => "app02.esat",
  hostname => "app02",
  interfaces => {
    eth0 => {
      bindings6 => [
        {
          address => "2a01:4f8:211:9d6::36",
          netmask => "ffff:ffff:ffff:ffff::",
          network => "2a01:4f8:211:9d6::"
        },
        {
          address => "fe80::5054:ff:fe45:9aec",
          netmask => "ffff:ffff:ffff:ffff::",
          network => "fe80::"
        }
      ],
      ip6 => "2a01:4f8:211:9d6::36",
      mac => "52:54:00:45:9a:ec",
      mtu => 1500,
      netmask6 => "ffff:ffff:ffff:ffff::",
      network6 => "2a01:4f8:211:9d6::"
    },
    lo => {
      bindings => [
        {
          address => "127.0.0.1",
          netmask => "255.0.0.0",
          network => "127.0.0.0"
        }
      ],
      bindings6 => [
        {
          address => "::1",
          netmask => "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
          network => "::1"
        }
      ],
      ip => "127.0.0.1",
      ip6 => "::1",
      mtu => 65536,
      netmask => "255.0.0.0",
      netmask6 => "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
      network => "127.0.0.0",
      network6 => "::1"
    }
  },
  ip6 => "2a01:4f8:211:9d6::36",
  mac => "52:54:00:45:9a:ec",
  mtu => 1500,
  netmask6 => "ffff:ffff:ffff:ffff::",
  network6 => "2a01:4f8:211:9d6::",
  primary => "eth0"
}
rski commented 7 years ago

Huh, I don't get it. The hash looks the same for me too. Is it because of the way it is accessed?

rski commented 7 years ago

what version of ruby are you using?

igalic commented 7 years ago

updated

rski commented 7 years ago

If you clone puppet-network in the system it is failing and run inside the puppet network folder facter -p network_primary_interface --custom-dir=./lib/facter/ does it work?

igalic commented 7 years ago
igalic@app02 /e/p/c/e/p/m/network ((107ed810…))> sudo -H /opt/puppetlabs/bin/facter -p network_primary_interface --custom-dir=./lib/facter/
eth0
igalic@app02 /e/p/c/e/p/m/network ((107ed810…))>
rski commented 7 years ago

so not an issue with the code per se, but a loading issue. I'm not sure if i can help debug that but maybe something wrong with the puppet-network version installed/loaded in the master/agent?

rski commented 7 years ago

Maybe running facter -d -p network_primary_interface will give a hint

igalic commented 7 years ago
igalic@app02 ~> sudo -H /opt/puppetlabs/bin/facter -d -p network_primary_interface
2016-12-04 21:56:36.277474 INFO  puppetlabs.facter - executed with command line: -d -p network_primary_interface.
2016-12-04 21:56:36.278503 INFO  leatherman.ruby:137 - ruby loaded from "/opt/puppetlabs/puppet/lib/libruby.so.2.1.0".
2016-12-04 21:56:36.296621 INFO  leatherman.ruby:186 - using ruby version 2.1.9
2016-12-04 21:56:36.296975 INFO  puppetlabs.facter - requested queries: network_primary_interface.
2016-12-04 21:56:36.297227 DEBUG puppetlabs.facter - fact "facterversion" has resolved to "3.5.0".
2016-12-04 21:56:36.297444 DEBUG puppetlabs.facter - fact "aio_agent_version" has resolved to "1.8.1".
2016-12-04 21:56:36.297863 DEBUG leatherman.file_util:65 - Error reading file: No such file or directory
2016-12-04 21:56:36.784480 DEBUG puppetlabs.facter - loading external fact directories from config file
2016-12-04 21:56:36.784835 DEBUG puppetlabs.facter - fact "facterversion" has resolved to "3.5.0".
2016-12-04 21:56:36.785084 DEBUG puppetlabs.facter - fact "aio_agent_version" has resolved to "1.8.1".
2016-12-04 21:56:36.785433 DEBUG puppetlabs.facter - searching "/opt/puppetlabs/facter/facts.d" for external facts.
2016-12-04 21:56:36.785724 DEBUG puppetlabs.facter - searching "/etc/facter/facts.d" for external facts.
2016-12-04 21:56:36.785982 DEBUG puppetlabs.facter - resolving facts from text file "/etc/facter/facts.d/vm_parent.txt".
2016-12-04 21:56:36.786312 DEBUG puppetlabs.facter - fact "vm_parent" has resolved to "tuna.esat".
2016-12-04 21:56:36.786562 DEBUG puppetlabs.facter - completed resolving facts from text file "/etc/facter/facts.d/vm_parent.txt".
2016-12-04 21:56:36.786808 DEBUG puppetlabs.facter - resolving facts from text file "/etc/facter/facts.d/vm_profile.txt".
2016-12-04 21:56:36.787050 DEBUG puppetlabs.facter - fact "vm_profile" has resolved to "internal".
2016-12-04 21:56:36.787280 DEBUG puppetlabs.facter - completed resolving facts from text file "/etc/facter/facts.d/vm_profile.txt".
2016-12-04 21:56:36.787509 DEBUG puppetlabs.facter - resolving facts from text file "/etc/facter/facts.d/role.txt".
2016-12-04 21:56:36.787747 DEBUG puppetlabs.facter - fact "role" has resolved to "app".
2016-12-04 21:56:36.787983 DEBUG puppetlabs.facter - completed resolving facts from text file "/etc/facter/facts.d/role.txt".
2016-12-04 21:56:36.788218 DEBUG puppetlabs.facter - skipping external facts for "/etc/puppetlabs/facter/facts.d": No such file or directory
2016-12-04 21:56:36.788451 DEBUG puppetlabs.facter - searching "/opt/puppetlabs/puppet/cache/facts.d" for external facts.
2016-12-04 21:56:36.788731 DEBUG puppetlabs.facter - loading all custom facts.
2016-12-04 21:56:36.788957 DEBUG puppetlabs.facter - loading custom fact directories from config file
2016-12-04 21:56:36.789251 DEBUG puppetlabs.facter - fact "agent_specified_environment" resolved to null and will not be added.
2016-12-04 21:56:36.789517 DEBUG puppetlabs.facter - fact "puppetversion" has resolved to "4.8.1".
2016-12-04 21:56:36.789778 DEBUG puppetlabs.facter - searching "/opt/puppetlabs/facter/facts.d" for external facts.
2016-12-04 21:56:36.790030 DEBUG puppetlabs.facter - searching "/etc/facter/facts.d" for external facts.
2016-12-04 21:56:36.790315 DEBUG puppetlabs.facter - resolving facts from text file "/etc/facter/facts.d/vm_parent.txt".
2016-12-04 21:56:36.790562 DEBUG puppetlabs.facter - fact "vm_parent" has changed from "tuna.esat" to "tuna.esat".
2016-12-04 21:56:36.790797 DEBUG puppetlabs.facter - completed resolving facts from text file "/etc/facter/facts.d/vm_parent.txt".
2016-12-04 21:56:36.791027 DEBUG puppetlabs.facter - resolving facts from text file "/etc/facter/facts.d/vm_profile.txt".
2016-12-04 21:56:36.791268 DEBUG puppetlabs.facter - fact "vm_profile" has changed from "internal" to "internal".
2016-12-04 21:56:36.791499 DEBUG puppetlabs.facter - completed resolving facts from text file "/etc/facter/facts.d/vm_profile.txt".
2016-12-04 21:56:36.791730 DEBUG puppetlabs.facter - resolving facts from text file "/etc/facter/facts.d/role.txt".
2016-12-04 21:56:36.791969 DEBUG puppetlabs.facter - fact "role" has changed from "app" to "app".
2016-12-04 21:56:36.792201 DEBUG puppetlabs.facter - completed resolving facts from text file "/etc/facter/facts.d/role.txt".
2016-12-04 21:56:36.792437 DEBUG puppetlabs.facter - skipping external facts for "/etc/puppetlabs/facter/facts.d": No such file or directory
2016-12-04 21:56:36.792685 DEBUG puppetlabs.facter - resolving networking facts.
2016-12-04 21:56:36.793003 DEBUG leatherman.execution:92 - executing command: /sbin/ip route show
2016-12-04 21:56:36.794014 DEBUG leatherman.execution:569 - process exited with status code 0.
2016-12-04 21:56:36.794354 DEBUG leatherman.execution:92 - executing command: /sbin/ip -6 route show
2016-12-04 21:56:36.795311 DEBUG | - 2002:94fb:bc57:1337::/64 dev eth0  proto kernel  metric 256  expires 86117sec
2016-12-04 21:56:36.795580 DEBUG | - 2a01:4f8:211:9d6::/64 dev eth0  proto kernel  metric 256
2016-12-04 21:56:36.795812 DEBUG | - fe80::/64 dev eth0  proto kernel  metric 256
2016-12-04 21:56:36.796045 DEBUG | - default via 2a01:4f8:211:9d6::2 dev eth0  metric 1024
2016-12-04 21:56:36.796274 DEBUG | - default via fe80::468a:5bff:fea0:2952 dev eth0  proto ra  metric 1024  expires 1517sec hoplimit 64
2016-12-04 21:56:36.796546 DEBUG leatherman.execution:569 - process exited with status code 0.
2016-12-04 21:56:36.796970 DEBUG puppetlabs.facter - hostname "app02" could not be resolved: hostname may not be externally resolvable.
2016-12-04 21:56:36.797293 DEBUG puppetlabs.facter - searching "/var/lib/dhclient" for dhclient lease files.
2016-12-04 21:56:36.797537 DEBUG puppetlabs.facter - searching "/var/lib/dhcp" for dhclient lease files.
2016-12-04 21:56:36.797791 DEBUG puppetlabs.facter - reading "/var/lib/dhcp/dhclient.leases" for dhclient lease information.
2016-12-04 21:56:36.798058 DEBUG puppetlabs.facter - searching "/var/lib/dhcp3" for dhclient lease files.
2016-12-04 21:56:36.798467 DEBUG puppetlabs.facter - searching "/var/lib/NetworkManager" for dhclient lease files.
2016-12-04 21:56:36.798808 DEBUG puppetlabs.facter - searching "/var/db" for dhclient lease files.
2016-12-04 21:56:36.799210 DEBUG leatherman.execution:92 - executing command: dhcpcd -U eth0
2016-12-04 21:56:36.799591 DEBUG leatherman.execution:425 - dhcpcd was not found on the PATH.
2016-12-04 21:56:36.799949 DEBUG leatherman.execution:92 - executing command: dhcpcd -U lo
2016-12-04 21:56:36.800284 DEBUG leatherman.execution:425 - dhcpcd was not found on the PATH.
2016-12-04 21:56:36.800615 DEBUG leatherman.execution:92 - executing command: /sbin/ip link show eth0
2016-12-04 21:56:36.801515 DEBUG | - 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000                                                                                                                                               
2016-12-04 21:56:36.801571 DEBUG | - link/ether 52:54:00:45:9a:ec brd ff:ff:ff:ff:ff:ff
2016-12-04 21:56:36.801603 DEBUG leatherman.execution:569 - process exited with status code 0.
2016-12-04 21:56:36.801632 DEBUG leatherman.execution:92 - executing command: /sbin/ip link show lo
2016-12-04 21:56:36.802245 DEBUG | - 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default
2016-12-04 21:56:36.802265 DEBUG | - link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2016-12-04 21:56:36.802302 DEBUG leatherman.execution:569 - process exited with status code 0.
2016-12-04 21:56:36.802321 DEBUG puppetlabs.facter - no primary interface found: using the first interface with an assigned address as the primary interface.                                                                                                                                         
2016-12-04 21:56:36.802346 DEBUG puppetlabs.facter - fact "ipaddress6_eth0" has resolved to "2a01:4f8:211:9d6::36".
2016-12-04 21:56:36.802361 DEBUG puppetlabs.facter - fact "ipaddress6" has resolved to "2a01:4f8:211:9d6::36".
2016-12-04 21:56:36.802379 DEBUG puppetlabs.facter - fact "netmask6_eth0" has resolved to "ffff:ffff:ffff:ffff::".
2016-12-04 21:56:36.802393 DEBUG puppetlabs.facter - fact "netmask6" has resolved to "ffff:ffff:ffff:ffff::".
2016-12-04 21:56:36.802407 DEBUG puppetlabs.facter - fact "network6_eth0" has resolved to "2a01:4f8:211:9d6::".
2016-12-04 21:56:36.802420 DEBUG puppetlabs.facter - fact "network6" has resolved to "2a01:4f8:211:9d6::".
2016-12-04 21:56:36.802442 DEBUG puppetlabs.facter - fact "macaddress_eth0" has resolved to "52:54:00:45:9a:ec".
2016-12-04 21:56:36.802456 DEBUG puppetlabs.facter - fact "macaddress" has resolved to "52:54:00:45:9a:ec".
2016-12-04 21:56:36.802474 DEBUG puppetlabs.facter - fact "mtu_eth0" has resolved to 1500.
2016-12-04 21:56:36.802492 DEBUG puppetlabs.facter - fact "ipaddress_lo" has resolved to "127.0.0.1".
2016-12-04 21:56:36.802506 DEBUG puppetlabs.facter - fact "netmask_lo" has resolved to "255.0.0.0".
2016-12-04 21:56:36.802520 DEBUG puppetlabs.facter - fact "network_lo" has resolved to "127.0.0.0".
2016-12-04 21:56:36.802535 DEBUG puppetlabs.facter - fact "ipaddress6_lo" has resolved to "::1".
2016-12-04 21:56:36.802550 DEBUG puppetlabs.facter - fact "netmask6_lo" has resolved to "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff".
2016-12-04 21:56:36.802564 DEBUG puppetlabs.facter - fact "network6_lo" has resolved to "::1".
2016-12-04 21:56:36.802579 DEBUG puppetlabs.facter - fact "mtu_lo" has resolved to 65536.
2016-12-04 21:56:36.802594 DEBUG puppetlabs.facter - fact "hostname" has resolved to "app02".
2016-12-04 21:56:36.802608 DEBUG puppetlabs.facter - fact "domain" has resolved to "esat".
2016-12-04 21:56:36.802621 DEBUG puppetlabs.facter - fact "fqdn" has resolved to "app02.esat".
2016-12-04 21:56:36.802635 DEBUG puppetlabs.facter - fact "interfaces" has resolved to "eth0,lo".
2016-12-04 21:56:36.802662 DEBUG puppetlabs.facter - fact "networking" has resolved to {
  domain => "esat",                                                                                                                                
  fqdn => "app02.esat",                                                                                                                            
  hostname => "app02",                                                                                                                             
  interfaces => {                                                                                                                                  
    eth0 => {                                                                                                                                      
      bindings6 => [                                                                                                                               
        {                                                                                                                                          
          address => "2a01:4f8:211:9d6::36",                                                                                                       
          netmask => "ffff:ffff:ffff:ffff::",                                                                                                      
          network => "2a01:4f8:211:9d6::"                                                                                                          
        },                                                                                                                                         
        {                                                                                                                                          
          address => "fe80::5054:ff:fe45:9aec",                                                                                                    
          netmask => "ffff:ffff:ffff:ffff::",                                                                                                      
          network => "fe80::"                                                                                                                      
        }                                                                                                                                          
      ],                                                                                                                                           
      ip6 => "2a01:4f8:211:9d6::36",
      mac => "52:54:00:45:9a:ec",
      mtu => 1500,
      netmask6 => "ffff:ffff:ffff:ffff::",
      network6 => "2a01:4f8:211:9d6::"
    },
    lo => {
      bindings => [
        {
          address => "127.0.0.1",
          netmask => "255.0.0.0",
          network => "127.0.0.0"
        }
      ],
      bindings6 => [
        {
          address => "::1",
          netmask => "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
          network => "::1"
        }
      ],
      ip => "127.0.0.1",
      ip6 => "::1",
      mtu => 65536,
      netmask => "255.0.0.0",
      netmask6 => "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
      network => "127.0.0.0",
      network6 => "::1"
    }
  },
  ip6 => "2a01:4f8:211:9d6::36",
  mac => "52:54:00:45:9a:ec",
  mtu => 1500,
  netmask6 => "ffff:ffff:ffff:ffff::",
  network6 => "2a01:4f8:211:9d6::",
  primary => "eth0"
}.
2016-12-04 21:56:36.802696 DEBUG puppetlabs.facter - fact "network_primary_interface" does not exist.

igalic@app02 ~>
rski commented 7 years ago

Huh this is why the old implementation failed:

No primary interface found: using the first interface with an assigned address as the primary interface.

Right so, it seems to me that it executes the code inside the network_primary_interface fact that calls facter to get the networking fact but then it comes back with fact "network_primary_interface" does not exist. what