diff options
author | Bradley A. Thornton <bthornto@thethorntons.net> | 2019-08-09 10:48:27 -0700 |
---|---|---|
committer | Bradley A. Thornton <bthornto@thethorntons.net> | 2019-08-09 10:48:27 -0700 |
commit | 5fb9df4e907a6ab2da7a6c2dafdec9c1971e8d44 (patch) | |
tree | 4459ed61d06c8d8caabbcc3ab36d84e27a919ee7 /plugins/modules/vyos_command.py | |
parent | 7b9a33a29007ed302c3001566061e22c514cde64 (diff) | |
download | vyos.vyos-5fb9df4e907a6ab2da7a6c2dafdec9c1971e8d44.tar.gz vyos.vyos-5fb9df4e907a6ab2da7a6c2dafdec9c1971e8d44.zip |
bt_blackked
Diffstat (limited to 'plugins/modules/vyos_command.py')
-rw-r--r-- | plugins/modules/vyos_command.py | 57 |
1 files changed, 30 insertions, 27 deletions
diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py index cf08ef6..a3593ba 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -17,11 +17,12 @@ # ANSIBLE_METADATA = { - 'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'network' + "metadata_version": "1.1", + "status": ["preview"], + "supported_by": "network", } + DOCUMENTATION = """ --- module: vyos_command @@ -143,11 +144,13 @@ from ansible.module_utils._text import to_text from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.network.common.parsing import Conditional from ansible.module_utils.network.common.utils import transform_commands, to_lines -from ansible_collections.vyos.vyos.plugins.module_utils.network. \ - vyos.vyos import run_commands +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( + run_commands, +) -from ansible_collections.vyos.vyos.plugins.module_utils.network. \ - vyos.vyos import vyos_argument_spec +from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.vyos import ( + vyos_argument_spec, +) def parse_commands(module, warnings): @@ -155,46 +158,49 @@ def parse_commands(module, warnings): if module.check_mode: for item in list(commands): - if not item['command'].startswith('show'): + if not item["command"].startswith("show"): warnings.append( - 'Only show commands are supported when using check mode, not ' - 'executing %s' % item['command']) + "Only show commands are supported when using check mode, not " + "executing %s" % item["command"] + ) commands.remove(item) return commands def main(): - spec = dict(commands=dict(type='list', required=True), - wait_for=dict(type='list', aliases=['waitfor']), - match=dict(default='all', choices=['all', 'any']), - retries=dict(default=10, type='int'), - interval=dict(default=1, type='int')) + spec = dict( + commands=dict(type="list", required=True), + wait_for=dict(type="list", aliases=["waitfor"]), + match=dict(default="all", choices=["all", "any"]), + retries=dict(default=10, type="int"), + interval=dict(default=1, type="int"), + ) spec.update(vyos_argument_spec) module = AnsibleModule(argument_spec=spec, supports_check_mode=True) warnings = list() - result = {'changed': False, 'warnings': warnings} + result = {"changed": False, "warnings": warnings} commands = parse_commands(module, warnings) - wait_for = module.params['wait_for'] or list() + wait_for = module.params["wait_for"] or list() try: conditionals = [Conditional(c) for c in wait_for] except AttributeError as exc: module.fail_json(msg=to_text(exc)) - retries = module.params['retries'] - interval = module.params['interval'] - match = module.params['match'] + retries = module.params["retries"] + interval = module.params["interval"] + match = module.params["match"] for _ in range(retries): responses = run_commands(module, commands) for item in list(conditionals): if item(responses): - if match == 'any': + if match == "any": conditionals = list() break conditionals.remove(item) @@ -206,16 +212,13 @@ def main(): if conditionals: failed_conditions = [item.raw for item in conditionals] - msg = 'One or more conditional statements have not been satisfied' + msg = "One or more conditional statements have not been satisfied" module.fail_json(msg=msg, failed_conditions=failed_conditions) - result.update({ - 'stdout': responses, - 'stdout_lines': list(to_lines(responses)), - }) + result.update({"stdout": responses, "stdout_lines": list(to_lines(responses))}) module.exit_json(**result) -if __name__ == '__main__': +if __name__ == "__main__": main() |