diff --git a/salt/modules/cmdmod.py b/salt/modules/cmdmod.py index 9334724a4741..06b490172310 100644 --- a/salt/modules/cmdmod.py +++ b/salt/modules/cmdmod.py @@ -337,6 +337,11 @@ def _run(cmd, ret['stderr'] = err ret['pid'] = proc.process.pid ret['retcode'] = proc.process.returncode + try: + __context__['retcode'] = ret['retcode'] + except NameError: + # Ignore the context error during grain generation + pass return ret