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

hponcfg: using CmdRunner (#5483)

* hponcfg: using CmdRunner

* add changelog fragment
This commit is contained in:
Alexei Znamensky 2022-11-07 18:43:21 +13:00 committed by GitHub
parent ac6ac73276
commit 7a9af2b601
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 14 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- hponcfg - refactored module to use ``CmdRunner`` to execute ``hponcfg`` (https://github.com/ansible-collections/community.general/pull/5483).

View file

@ -73,12 +73,11 @@ EXAMPLES = r'''
executable: /opt/hp/tools/hponcfg executable: /opt/hp/tools/hponcfg
''' '''
from ansible_collections.community.general.plugins.module_utils.module_helper import ( from ansible_collections.community.general.plugins.module_utils.cmd_runner import CmdRunner, cmd_runner_fmt
CmdModuleHelper, ArgFormat from ansible_collections.community.general.plugins.module_utils.module_helper import ModuleHelper
)
class HPOnCfg(CmdModuleHelper): class HPOnCfg(ModuleHelper):
module = dict( module = dict(
argument_spec=dict( argument_spec=dict(
src=dict(type='path', required=True, aliases=['path']), src=dict(type='path', required=True, aliases=['path']),
@ -88,19 +87,22 @@ class HPOnCfg(CmdModuleHelper):
) )
) )
command_args_formats = dict( command_args_formats = dict(
src=dict(fmt=["-f", "{0}"]), src=cmd_runner_fmt.as_opt_val("-f"),
verbose=dict(fmt="-v", style=ArgFormat.BOOLEAN), verbose=cmd_runner_fmt.as_bool("-v"),
minfw=dict(fmt=["-m", "{0}"]), minfw=cmd_runner_fmt.as_opt_val("-m"),
) )
check_rc = True
def __init_module__(self):
self.command = self.vars.executable
# Consider every action a change (not idempotent yet!)
self.changed = True
def __run__(self): def __run__(self):
self.run_command(params=['src', 'verbose', 'minfw']) runner = CmdRunner(
self.module,
self.vars.executable,
self.command_args_formats,
check_rc=True,
)
runner(['src', 'verbose', 'minfw']).run()
# Consider every action a change (not idempotent yet!)
self.changed = True
def main(): def main():