From 9069a681aabdef45aa201bf39577405070d63af6 Mon Sep 17 00:00:00 2001 From: Martin Krizek Date: Tue, 25 Jun 2019 17:13:35 +0200 Subject: [PATCH] sysctl: fix 'err' referenced before assignment (#58161) * sysctl: fix 'err' referenced before assignment Fixes #58158 * Add changelog --- .../58158-sysctl-fix-referenced-before-assignment.yaml | 2 ++ lib/ansible/modules/system/sysctl.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/58158-sysctl-fix-referenced-before-assignment.yaml diff --git a/changelogs/fragments/58158-sysctl-fix-referenced-before-assignment.yaml b/changelogs/fragments/58158-sysctl-fix-referenced-before-assignment.yaml new file mode 100644 index 00000000000..591e57d36f4 --- /dev/null +++ b/changelogs/fragments/58158-sysctl-fix-referenced-before-assignment.yaml @@ -0,0 +1,2 @@ +bugfixes: + - sysctl - fix err referenced before assignment (https://github.com/ansible/ansible/issues/58158) diff --git a/lib/ansible/modules/system/sysctl.py b/lib/ansible/modules/system/sysctl.py index 2a09aa6ff55..34b1d00ecee 100644 --- a/lib/ansible/modules/system/sysctl.py +++ b/lib/ansible/modules/system/sysctl.py @@ -271,7 +271,6 @@ class SysctlModule(object): # Run sysctl -p def reload_sysctl(self): - # do it if self.platform == 'freebsd': # freebsd doesn't support -p, so reload the sysctl service rc, out, err = self.module.run_command('/etc/rc.d/sysctl reload', environ_update=self.LANG_ENV) @@ -282,10 +281,16 @@ class SysctlModule(object): rc = 0 if k != self.args['name']: rc = self.set_token_value(k, v) + # FIXME this check is probably not needed as set_token_value would fail_json if rc != 0 if rc != 0: break if rc == 0 and self.args['state'] == "present": rc = self.set_token_value(self.args['name'], self.args['value']) + + # set_token_value would have called fail_json in case of failure + # so return here and do not continue to the error processing below + # https://github.com/ansible/ansible/issues/58158 + return else: # system supports reloading via the -p flag to sysctl, so we'll use that sysctl_args = [self.sysctl_cmd, '-p', self.sysctl_file]