Skip to content

Commit

Permalink
Fix edit_config multiline commands on IOS (ansible#35375)
Browse files Browse the repository at this point in the history
* Fix edit_config multiline commands on IOS

The current code for multiline commands in IOS is broken: If you
pass a dict containing a command, prompt and answer it is seen
later as unicode string, but if you do a json.loads it fails
as the keys/values are enclosed in single quotes but JSON requires
double quotes.

Fixes ansible#23539

* Fix pep8

* Use ast literal_eval

It's safe to use, as it is just for types and wont execute arbitrary code.
  • Loading branch information
rcarrillocruz authored Jan 29, 2018
1 parent 5f12546 commit d178df8
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/ansible/plugins/cliconf/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import ast
import re
import json

Expand Down Expand Up @@ -71,7 +72,7 @@ def get_config(self, source='running', flags=None):
def edit_config(self, command):
for cmd in chain(['configure terminal'], to_list(command), ['end']):
try:
cmd = json.loads(cmd)
cmd = ast.literal_eval(cmd)
command = cmd['command']
prompt = cmd['prompt']
answer = cmd['answer']
Expand Down

0 comments on commit d178df8

Please sign in to comment.