From 8c8c63110ea62b63e6960b56b7af149fcb9a2284 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Sun, 1 Nov 2015 12:58:20 -0800 Subject: [PATCH] Move existing check for root before we make expensive network calls --- lib/ansible/modules/extras/packaging/os/dnf.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/extras/packaging/os/dnf.py b/lib/ansible/modules/extras/packaging/os/dnf.py index c606f51c80..96097e4afe 100644 --- a/lib/ansible/modules/extras/packaging/os/dnf.py +++ b/lib/ansible/modules/extras/packaging/os/dnf.py @@ -241,9 +241,6 @@ def _mark_package_install(module, base, pkg_spec): def ensure(module, base, state, names): - if not util.am_i_root(): - module.fail_json(msg="This command has to be run under the root user.") - if names == ['*'] and state == 'latest': base.upgrade_all() else: @@ -337,12 +334,20 @@ def main(): mutually_exclusive=[['name', 'list']], supports_check_mode=True) params = module.params - base = _base( - module, params['conf_file'], params['disable_gpg_check'], - params['disablerepo'], params['enablerepo']) if params['list']: + base = _base( + module, params['conf_file'], params['disable_gpg_check'], + params['disablerepo'], params['enablerepo']) list_items(module, base, params['list']) else: + # Note: base takes a long time to run so we want to check for failure + # before running it. + if not util.am_i_root(): + module.fail_json(msg="This command has to be run under the root user.") + base = _base( + module, params['conf_file'], params['disable_gpg_check'], + params['disablerepo'], params['enablerepo']) + ensure(module, base, params['state'], params['name'])