1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

hponcfg - revamped the module using ModuleHelper (#3840) (#3891)

* hponcfg - revamped the module using ModuleHelper

* added changelog fragment

* fixed imports

* Update plugins/modules/remote_management/hpilo/hponcfg.py

* fixed

(cherry picked from commit 7cbe1bcf63)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2021-12-11 21:35:23 +01:00 committed by GitHub
parent 102456d033
commit 8823e5c061
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 23 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- hponcfg - revamped module using ModuleHelper (https://github.com/ansible-collections/community.general/pull/3840).

View file

@ -69,12 +69,13 @@ EXAMPLES = r'''
executable: /opt/hp/tools/hponcfg executable: /opt/hp/tools/hponcfg
''' '''
from ansible.module_utils.basic import AnsibleModule from ansible_collections.community.general.plugins.module_utils.module_helper import (
CmdModuleHelper, ArgFormat
)
def main(): class HPOnCfg(CmdModuleHelper):
module = dict(
module = AnsibleModule(
argument_spec=dict( argument_spec=dict(
src=dict(type='path', required=True, aliases=['path']), src=dict(type='path', required=True, aliases=['path']),
minfw=dict(type='str'), minfw=dict(type='str'),
@ -82,29 +83,24 @@ def main():
verbose=dict(default=False, type='bool'), verbose=dict(default=False, type='bool'),
) )
) )
command_args_formats = dict(
src=dict(fmt=["-f", "{0}"]),
verbose=dict(fmt="-v", style=ArgFormat.BOOLEAN),
minfw=dict(fmt=["-m", "{0}"]),
)
check_rc = True
# Consider every action a change (not idempotent yet!) def __init_module__(self):
changed = True self.command = self.vars.executable
# Consider every action a change (not idempotent yet!)
self.changed = True
src = module.params['src'] def __run__(self):
minfw = module.params['minfw'] self.run_command(params=['src', 'verbose', 'minfw'])
executable = module.params['executable']
verbose = module.params['verbose']
options = ' -f %s' % src
if verbose: def main():
options += ' -v' HPOnCfg.execute()
if minfw:
options += ' -m %s' % minfw
rc, stdout, stderr = module.run_command('%s %s' % (executable, options))
if rc != 0:
module.fail_json(rc=rc, msg="Failed to run hponcfg", stdout=stdout, stderr=stderr)
module.exit_json(changed=changed, stdout=stdout, stderr=stderr)
if __name__ == '__main__': if __name__ == '__main__':