diff options
Diffstat (limited to 'plugins/modules/vyos_command.py')
| -rw-r--r-- | plugins/modules/vyos_command.py | 58 | 
1 files changed, 28 insertions, 30 deletions
| diff --git a/plugins/modules/vyos_command.py b/plugins/modules/vyos_command.py index 3570f20..a3593ba 100644 --- a/plugins/modules/vyos_command.py +++ b/plugins/modules/vyos_command.py @@ -16,9 +16,11 @@  # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.  # -ANSIBLE_METADATA = {'metadata_version': '1.1', -                    'status': ['preview'], -                    'supported_by': 'network'} +ANSIBLE_METADATA = { +    "metadata_version": "1.1", +    "status": ["preview"], +    "supported_by": "network", +}  DOCUMENTATION = """ @@ -142,12 +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 vyos_argument_spec +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, +)  def parse_commands(module, warnings): @@ -155,10 +158,10 @@ 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) @@ -167,13 +170,11 @@ def parse_commands(module, warnings):  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') +        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) @@ -181,25 +182,25 @@ def main():      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) @@ -211,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() | 
