Simplify logic by using required=True.
This commit is contained in:
parent
e7405643e1
commit
98dcb3a006
1 changed files with 21 additions and 27 deletions
|
@ -355,8 +355,8 @@ def upgrade_packages(module):
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
name = dict(),
|
name = dict(required=True),
|
||||||
state = dict(choices=['absent', 'installed', 'latest', 'present', 'removed']),
|
state = dict(required=True, choices=['absent', 'installed', 'latest', 'present', 'removed']),
|
||||||
),
|
),
|
||||||
supports_check_mode = True
|
supports_check_mode = True
|
||||||
)
|
)
|
||||||
|
@ -371,10 +371,6 @@ def main():
|
||||||
result['name'] = name
|
result['name'] = name
|
||||||
result['state'] = state
|
result['state'] = state
|
||||||
|
|
||||||
if name:
|
|
||||||
if not state:
|
|
||||||
module.fail_json(msg="missing required arguments: state")
|
|
||||||
|
|
||||||
if name == '*':
|
if name == '*':
|
||||||
if state != 'latest':
|
if state != 'latest':
|
||||||
module.fail_json(msg="the package name '*' is only valid when using state=latest")
|
module.fail_json(msg="the package name '*' is only valid when using state=latest")
|
||||||
|
@ -396,8 +392,6 @@ def main():
|
||||||
(rc, stdout, stderr, changed) = package_absent(name, installed_state, module)
|
(rc, stdout, stderr, changed) = package_absent(name, installed_state, module)
|
||||||
elif state == 'latest':
|
elif state == 'latest':
|
||||||
(rc, stdout, stderr, changed) = package_latest(name, installed_state, pkg_spec, module)
|
(rc, stdout, stderr, changed) = package_latest(name, installed_state, pkg_spec, module)
|
||||||
else:
|
|
||||||
module.fail_json(msg="Something is broken, you should never end up here")
|
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
if stderr:
|
if stderr:
|
||||||
|
|
Loading…
Reference in a new issue