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

Fixes #12310 - clean facter to force new scan #115

Merged
merged 1 commit into from Aug 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions root/usr/bin/discovery-register
Expand Up @@ -63,20 +63,23 @@ facts = Hash[Facter.to_hash.select {|k,v| k =~ /address|hardware|manufacturer|pr
facts.keys.sort.each {|k| log_msg " #{k}: #{facts[k]}"}

# check every 15 minutes but only upload on changes
i = cmdline("fdi.cachefacts", 0).to_i rescue 0
upload_sleep = cmdline("fdi.uploadsleep", 60 * 15).to_i rescue (60 * 15)
extra_initial_uploads = cmdline("fdi.cachefacts", 0).to_i rescue 0
while true do
uninteresting_facts=/kernel|operatingsystem|osfamily|ruby|path|time|swap|free|filesystem|version|selinux/i
# force facter to do new system scan (we default to 15 minute intervals which is safe)
Facter.clear
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is essentially the only change, the rest is just renamed local variable, shuffling with order of lines for better readability and an extra debug message.

facts = Facter.to_hash.reject! {|k,v| k =~ uninteresting_facts }
unless YAML.load(read_cache) == facts
log_msg "Fact cache invalid, reloading to foreman"
write_cache(YAML.dump(facts)) if upload
else
log_msg "No change in facts (next check in #{upload_sleep} seconds)"
end
sleep upload_sleep
if i > 0
log_msg "Clearing cache after boot, will repeat #{i} times"
if extra_initial_uploads > 0
log_msg "Performing extra initial fact upload as defined by fdi.cachefacts (#{i} left)"
clear_cache
Facter.clear
i -= 1
extra_initial_uploads -= 1
end
end