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

Do not use "del os.environ" as the variable might not exist #1142

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion plugins/module_utils/ansible_freeipa_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def temp_kdestroy(ccache_dir, ccache_name):
"""Destroy temporary ticket and remove temporary ccache."""
if ccache_name is not None:
run([paths.KDESTROY, '-c', ccache_name], raiseonerr=False)
del os.environ['KRB5CCNAME']
os.environ.pop('KRB5CCNAME', None)
if ccache_dir is not None:
shutil.rmtree(ccache_dir, ignore_errors=True)

Expand Down
2 changes: 1 addition & 1 deletion roles/ipaclient/library/ipaclient_fix_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def main():
else:
get_ca_certs(fstore, options, servers[0], basedn, realm)
changed = True
del os.environ['KRB5_CONFIG']
os.environ.pop('KRB5_CONFIG', None)
except errors.FileError as e:
module.fail_json(msg='%s' % e)
except Exception as e:
Expand Down
2 changes: 1 addition & 1 deletion roles/ipaclient/library/ipaclient_get_otp.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def temp_kdestroy(ccache_dir, ccache_name):
"""Destroy temporary ticket and remove temporary ccache."""
if ccache_name is not None:
run([paths.KDESTROY, '-c', ccache_name], raiseonerr=False)
del os.environ['KRB5CCNAME']
os.environ.pop('KRB5CCNAME', None)
if ccache_dir is not None:
shutil.rmtree(ccache_dir, ignore_errors=True)

Expand Down
2 changes: 1 addition & 1 deletion roles/ipaclient/library/ipaclient_join.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def main():
get_ca_cert(fstore, options, servers[0], basedn)
else:
get_ca_certs(fstore, options, servers[0], basedn, realm)
del os.environ['KRB5_CONFIG']
os.environ.pop('KRB5_CONFIG', None)
except errors.FileError as e:
module.fail_json(msg='%s' % e)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions roles/ipareplica/library/ipareplica_prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ def main():
raise errors.ACIError(info="Not authorized")

if installer._ccache is None:
del os.environ['KRB5CCNAME']
os.environ.pop('KRB5CCNAME', None)
else:
os.environ['KRB5CCNAME'] = installer._ccache

Expand Down Expand Up @@ -873,7 +873,7 @@ def main():
if add_to_ipaservers:
# use user's credentials when the server host is not ipaservers
if installer._ccache is None:
del os.environ['KRB5CCNAME']
os.environ.pop('KRB5CCNAME', None)
else:
os.environ['KRB5CCNAME'] = installer._ccache

Expand Down
2 changes: 1 addition & 1 deletion roles/ipaserver/library/ipaserver_get_connected_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def temp_kdestroy(ccache_dir, ccache_name):
"""Destroy temporary ticket and remove temporary ccache."""
if ccache_name is not None:
run([paths.KDESTROY, '-c', ccache_name], raiseonerr=False)
del os.environ['KRB5CCNAME']
os.environ.pop('KRB5CCNAME', None)
if ccache_dir is not None:
shutil.rmtree(ccache_dir, ignore_errors=True)

Expand Down