From 7fe64ef9b89428d82b5851b5d33b5bba4beb2082 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Tue, 6 Sep 2016 15:33:55 -0400 Subject: [PATCH] bug fix for AttributeError: 'str' object has no attribute 'get' Exception thrown when using cli transport in eos but piping the command through json * eos now checks for `| json` and automatically changes the output type * adds back import of Command object tested on EOS 4.15.4F --- lib/ansible/module_utils/eos.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/eos.py b/lib/ansible/module_utils/eos.py index e0a6eff44a..0511cccbd9 100644 --- a/lib/ansible/module_utils/eos.py +++ b/lib/ansible/module_utils/eos.py @@ -31,6 +31,7 @@ import re from ansible.module_utils.basic import json from ansible.module_utils.network import ModuleStub, NetworkError, NetworkModule from ansible.module_utils.network import add_argument, register_transport, to_list +from ansible.module_utils.netcli import Command from ansible.module_utils.shell import CliBase from ansible.module_utils.urls import fetch_url, url_argument_spec @@ -307,9 +308,12 @@ def prepare_commands(commands): :returns: list of dict objects """ jsonify = lambda x: '%s | json' % x - for cmd in to_list(commands): - if cmd.output == 'json': + for item in to_list(commands): + if item.output == 'json': cmd = jsonify(cmd) + elif item.command.endswith('| json'): + item.output = 'json' + cmd = str(item) else: - cmd = str(cmd) + cmd = str(item) yield cmd