diff options
| author | ansible-zuul[bot] <48994755+ansible-zuul[bot]@users.noreply.github.com> | 2019-08-09 18:52:36 +0000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-08-09 18:52:36 +0000 | 
| commit | fbe294b702e757252a66f64edf66bce060e87494 (patch) | |
| tree | 6910d3c526815c0e21f20cfbccd08bea727cf11c /plugins/modules/vyos_command.py | |
| parent | 4a485b24db1abf87cdf0d4ef2f7acb1159aaab68 (diff) | |
| parent | 5fb9df4e907a6ab2da7a6c2dafdec9c1971e8d44 (diff) | |
| download | vyos-ansible-collection-fbe294b702e757252a66f64edf66bce060e87494.tar.gz vyos-ansible-collection-fbe294b702e757252a66f64edf66bce060e87494.zip | |
Merge pull request #8 from ansible-network/bt_blacked
Bt blacked
Reviewed-by: Paul Belanger
             https://github.com/pabelanger
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() | 
