Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fact for nomad_node_id #63

Merged
merged 3 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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+})
sebastianrakel marked this conversation as resolved.
Show resolved Hide resolved
expect(r.stdout).to match(%r{nomad_version: \S+})
end
end
# rubocop:enable RSpec/RepeatedExample
end
end