a99be9f861
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
30 lines
724 B
Ruby
30 lines
724 B
Ruby
# 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
|