Skip to content

Commit

Permalink
Merge pull request #224 from bastelfreak/cleanup
Browse files Browse the repository at this point in the history
pe_status_check_role: Cleanup class matching
  • Loading branch information
MartyEwings authored Apr 12, 2024
2 parents 3ecd685 + 6f23738 commit f5977ae
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/facter/pe_status_check_role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
require_relative '../shared/pe_status_check'
classfile = Puppet.settings[:classfile]

node_profiles = []
# Turn the list of infra roles defined in the module constant into a regex we can use with grep()
profile_regex = %r{^puppet_enterprise::profile::(#{PEStatusCheck.infra_profiles.join('|')})$}

begin
File.open(classfile).grep(profile_regex) do |profile|
node_profiles = File.open(classfile).grep(profile_regex) { |profile|
# Strip the leading 'puppet_enterprise::profile::' from each match
short_profile = profile.split(':')[-1].chomp
# Add unique entries to the node_profiles array by doing a bitwise or between it and the current match
# e.g. `['foo', 'bar'] | ['bar', 'baz']` produces `['foo', 'bar', 'baz']`
node_profiles |= [short_profile]
end
profile.split(':')[-1].chomp
}.uniq

if node_profiles.include?('certificate_authority') && node_profiles.include?('database')
then 'primary'
Expand Down

0 comments on commit f5977ae

Please sign in to comment.