Add networkctl fact
ci/woodpecker/pr/puppet-lint Pipeline was successful
ci/woodpecker/pr/yamllint Pipeline was successful
ci/woodpecker/pr/ruby-validate Pipeline was successful
ci/woodpecker/pr/erb-validate Pipeline was successful
ci/woodpecker/pr/bolt-validate Pipeline was successful
ci/woodpecker/pr/epp-validate Pipeline was successful
ci/woodpecker/pr/puppet-validate Pipeline was successful
ci/woodpecker/pr/ruby-check Pipeline was successful

This commit is contained in:
2026-11-15 18:05:21 +11:00
parent 452acfacd9
commit a99be9f861
+29
View File
@@ -0,0 +1,29 @@
# frozen_string_literal: true
require 'facter'
require 'json'
# Exposes systemd-networkd link state from `networkctl --json=short`, keyed by interface name.
module NetworkctlFact
module_function
def parse(output)
JSON.parse(output).fetch('Interfaces').to_h { |iface| [iface['Name'], iface] }
end
def resolve
output = Facter::Core::Execution.execute('networkctl --json=short 2>/dev/null', on_fail: nil)
return nil if output.to_s.empty?
parse(output)
rescue StandardError
nil
end
end
Facter.add(:networkctl) do
confine kernel: 'Linux'
confine { Facter::Core::Execution.which('networkctl') }
confine { File.directory?('/run/systemd/netif') }
setcode { NetworkctlFact.resolve }
end