Skip to content

Commit

Permalink
server_facts: Switch from legacy to structured facts
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Aug 3, 2024
1 parent 5084326 commit 1a2a567
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/rspec-puppet/support.rb
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,7 @@ def server_facts_hash
server_facts['serverversion'] = Puppet.version.to_s

# And then add the server name and IP
{ 'servername' => 'fqdn',
'serverip' => 'ipaddress' }.each do |var, fact|
{ 'servername' => 'networking.fqdn', 'serverip' => 'networking.ip' }.each do |var, fact|
if (value = Puppet.runtime[:facter].value(fact))
server_facts[var] = value
else
Expand All @@ -311,8 +310,8 @@ def server_facts_hash
end

if server_facts['servername'].nil?
host = Puppet.runtime[:facter].value(:hostname)
server_facts['servername'] = if (domain = Puppet.runtime[:facter].value(:domain))
host = Puppet.runtime[:facter].value('networking.hostname')
server_facts['servername'] = if (domain = Puppet.runtime[:facter].value('networking.domain'))
[host, domain].join('.')
else
host
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/server_facts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
describe 'server_facts' do
let(:facts) do
{
ipaddress: '192.168.1.10'
'networking' => { 'ip' => '192.168.1.10' }
}
end
let(:node) { 'test123.test.com' }
Expand Down

0 comments on commit 1a2a567

Please sign in to comment.