Skip to content

Commit

Permalink
Add fact for nomad_node_id
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianrakel committed May 23, 2022
1 parent 4896c7a commit c494807
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/facter/nomad_node_id.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# nomad_node_id.rb
#
Facter.add(:nomad_node_id) do
confine do
File.readable?('/var/lib/nomad/server/node-id')
end
setcode do
File.read('/var/lib/nomad/server/node-id').chomp
rescue StandardError
nil
end
end
48 changes: 48 additions & 0 deletions spec/acceptance/fact_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# frozen_string_literal: true

require 'spec_helper_acceptance'

describe 'nomad class' do
context 'facts' do
pp = <<-EOS
class { 'nomad':
config_hash => {
region => 'us-west',
datacenter => 'ptk',
log_level => 'INFO',
bind_addr => "0.0.0.0",
data_dir => "/var/lib/nomad",
server => {
enabled => true,
bootstrap_expect => 1
}
}
}
EOS

fact_notices = <<-EOS
notify{"nomad_node_id: ${facts['nomad_node_id']}":}
notify{"nomad_version: ${facts['nomad_version']}":}
EOS

# rubocop:disable RSpec/RepeatedExample
it 'outputs nomad facts when not installed' do
apply_manifest(fact_notices, catch_failures: true) do |r|
expect(r.stdout).to match(%r{nomad_node_id: \S+})
expect(r.stdout).to match(%r{nomad_version: \S+})
end
end

it 'sets up nomad' do
apply_manifest(pp, catch_failures: true)
end

it 'outputs nomad facts when installed' do
apply_manifest(fact_notices, catch_failures: true) do |r|
expect(r.stdout).to match(%r{nomad_node_id: \S+})
expect(r.stdout).to match(%r{nomad_version: \S+})
end
end
# rubocop:enable RSpec/RepeatedExample
end
end

0 comments on commit c494807

Please sign in to comment.