diff --git a/lib/ansible/modules/extras/packaging/os/zypper_repository.py b/lib/ansible/modules/extras/packaging/os/zypper_repository.py
index e6e263c3e5..db553970e8 100644
--- a/lib/ansible/modules/extras/packaging/os/zypper_repository.py
+++ b/lib/ansible/modules/extras/packaging/os/zypper_repository.py
@@ -280,9 +280,10 @@ def get_zypper_version(module):
 
 def runrefreshrepo(module, auto_import_keys=False, shortname=None):
     "Forces zypper to refresh repo metadata."
-    cmd = _get_cmd('refresh', '--force')
     if auto_import_keys:
-        cmd.append('--gpg-auto-import-keys')
+        cmd = _get_cmd('--gpg-auto-import-keys', 'refresh', '--force')
+    else:
+        cmd = _get_cmd('refresh', '--force')
     if shortname is not None:
         cmd.extend(['-r', shortname])