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)
* hponcfg - revamped the module using ModuleHelper * added changelog fragment * fixed imports * Update plugins/modules/remote_management/hpilo/hponcfg.py * fixed
This commit is contained in:
parent
2547932e3d
commit
7cbe1bcf63
2 changed files with 21 additions and 23 deletions
2
changelogs/fragments/3840-hponcfg-mh-revamp.yaml
Normal file
2
changelogs/fragments/3840-hponcfg-mh-revamp.yaml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
minor_changes:
|
||||||
|
- hponcfg - revamped module using ModuleHelper (https://github.com/ansible-collections/community.general/pull/3840).
|
|
@ -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
|
||||||
|
|
||||||
|
def __init_module__(self):
|
||||||
|
self.command = self.vars.executable
|
||||||
# Consider every action a change (not idempotent yet!)
|
# Consider every action a change (not idempotent yet!)
|
||||||
changed = True
|
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__':
|
||||||
|
|
Loading…
Reference in a new issue