From e9fc2df1bc041ea174022553c8a90ed3b4bf6b0e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 29 May 2019 13:51:35 +1000 Subject: [PATCH] Clear out old facts In debugging why I631e3e3592a9be5c7da642cf34eec6d9758bf161 was not rolling out to the zuul executors, I eventually found /etc/facter/facts.d/ansible.json was present on a number of hosts and effectively pinning the project-config checkout to an old reference. Given the dates around file creation and the pinned change number, it seems very likely something happened during the openstack->opendev transition where some hosts had ansible run with a specific project_config_ref set as a fact. Although the fact is now unset, nothing will ever clear the old ansible.json which keeps applying. We could remove all stale files by hand; but a) it's not clear where it ran (although likely only hosts starting with z*) and b) we leave a chance for it to happen again. We could clear this after every puppet run; but it seems like this role should leave the system largely in the state it ran puppet in. Thus this clears out the file before the puppet run if no facts are given. This should fix our immediate issue on all hosts. Change-Id: I96adf4fb77f06b18fe73b6f10d1b07b7fe44385f --- library/puppet | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/library/puppet b/library/puppet index 2972448..be79afe 100644 --- a/library/puppet +++ b/library/puppet @@ -208,11 +208,22 @@ def main(): module.fail_json( msg="Puppet agent state could not be determined.") - if module.params['facts'] and not module.check_mode: - _write_structured_data( - _get_facter_dir(), - module.params['facter_basename'], - module.params['facts']) + if not module.check_mode: + if module.params['facts']: + _write_structured_data( + _get_facter_dir(), + module.params['facter_basename'], + module.params['facts']) + else: + # If facts argument is removed after having run, we have + # an old fact file that keeps applying. Ensure any old + # facts are cleared. + old_facts_file = os.path.join(_get_facter_dir(), + "{0}.json".format( + module.params['facter_basename'])) + if os.path.exists(old_facts_file): + os.unlink(old_facts_file) + if TIMEOUT_CMD: base_cmd = "%(timeout_cmd)s -s 9 %(timeout)s %(puppet_cmd)s" % dict(