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(