diff --git a/lib/ansible/modules/network/ios/ios_config.py b/lib/ansible/modules/network/ios/ios_config.py index 33535648e0..b2e2162ee8 100644 --- a/lib/ansible/modules/network/ios/ios_config.py +++ b/lib/ansible/modules/network/ios/ios_config.py @@ -321,6 +321,13 @@ def check_args(module, warnings): 'single character') +def edit_config_or_macro(connection, commands): + if "macro name" in commands[0]: + connection.edit_macro(candidate=commands) + else: + connection.edit_config(candidate=commands) + + def get_candidate_config(module): candidate = '' if module.params['src']: @@ -457,7 +464,7 @@ def main(): # them with the current running config if not module.check_mode: if commands: - connection.edit_config(candidate=commands) + edit_config_or_macro(connection, commands) if banner_diff: connection.edit_banner(candidate=json.dumps(banner_diff), multiline_delimiter=module.params['multiline_delimiter']) diff --git a/lib/ansible/plugins/cliconf/ios.py b/lib/ansible/plugins/cliconf/ios.py index cb59401d54..095a4ad7cc 100644 --- a/lib/ansible/plugins/cliconf/ios.py +++ b/lib/ansible/plugins/cliconf/ios.py @@ -151,6 +151,32 @@ class Cliconf(CliconfBase): resp['response'] = results return resp + def edit_macro(self, candidate=None, commit=True, replace=None, comment=None): + resp = {} + operations = self.get_device_operations() + self.check_edit_config_capabiltiy(operations, candidate, commit, replace, comment) + + results = [] + requests = [] + if commit: + commands = '' + for line in candidate: + if line != 'None': + commands += (' ' + line + '\n') + self.send_command('config terminal', sendonly=True) + obj = {'command': commands, 'sendonly': True} + results.append(self.send_command(**obj)) + requests.append(commands) + + self.send_command('end', sendonly=True) + time.sleep(0.1) + results.append(self.send_command('\n')) + requests.append('\n') + + resp['request'] = requests + resp['response'] = results + return resp + def get(self, command=None, prompt=None, answer=None, sendonly=False, output=None): if not command: raise ValueError('must provide value of command to execute')