|
|
@ -123,8 +123,9 @@ import re
|
|
|
|
from copy import deepcopy
|
|
|
|
from copy import deepcopy
|
|
|
|
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.network.common.utils import remove_default_spec
|
|
|
|
from ansible.module_utils.network.common.utils import remove_default_spec, validate_ip_address
|
|
|
|
from ansible.module_utils.network.ios.ios import get_config, load_config
|
|
|
|
from ansible.module_utils.network.ios.ios import get_config, load_config
|
|
|
|
|
|
|
|
from ansible.module_utils.network.ios.ios import get_capabilities
|
|
|
|
from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args
|
|
|
|
from ansible.module_utils.network.ios.ios import ios_argument_spec, check_args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -136,7 +137,7 @@ def validate_size(value, module):
|
|
|
|
return value
|
|
|
|
return value
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def map_obj_to_commands(updates, module):
|
|
|
|
def map_obj_to_commands(updates, module, os_version):
|
|
|
|
commands = list()
|
|
|
|
commands = list()
|
|
|
|
want, have = updates
|
|
|
|
want, have = updates
|
|
|
|
for w in want:
|
|
|
|
for w in want:
|
|
|
@ -150,7 +151,10 @@ def map_obj_to_commands(updates, module):
|
|
|
|
|
|
|
|
|
|
|
|
if state == 'absent' and w in have:
|
|
|
|
if state == 'absent' and w in have:
|
|
|
|
if dest == 'host':
|
|
|
|
if dest == 'host':
|
|
|
|
commands.append('no logging host {0}'.format(name))
|
|
|
|
if '12.' in os_version:
|
|
|
|
|
|
|
|
commands.append('no logging {0}'.format(name))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
commands.append('no logging host {0}'.format(name))
|
|
|
|
elif dest:
|
|
|
|
elif dest:
|
|
|
|
commands.append('no logging {0}'.format(dest))
|
|
|
|
commands.append('no logging {0}'.format(dest))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
@ -164,7 +168,10 @@ def map_obj_to_commands(updates, module):
|
|
|
|
commands.append('logging facility {0}'.format(facility))
|
|
|
|
commands.append('logging facility {0}'.format(facility))
|
|
|
|
|
|
|
|
|
|
|
|
if dest == 'host':
|
|
|
|
if dest == 'host':
|
|
|
|
commands.append('logging host {0}'.format(name))
|
|
|
|
if '12.' in os_version:
|
|
|
|
|
|
|
|
commands.append('logging {0}'.format(name))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
commands.append('logging host {0}'.format(name))
|
|
|
|
|
|
|
|
|
|
|
|
elif dest == 'on':
|
|
|
|
elif dest == 'on':
|
|
|
|
commands.append('logging on')
|
|
|
|
commands.append('logging on')
|
|
|
@ -176,11 +183,11 @@ def map_obj_to_commands(updates, module):
|
|
|
|
commands.append('logging buffered {0}'.format(size))
|
|
|
|
commands.append('logging buffered {0}'.format(size))
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
dest_cmd = 'logging {0}'.format(dest)
|
|
|
|
if dest:
|
|
|
|
if level:
|
|
|
|
dest_cmd = 'logging {0}'.format(dest)
|
|
|
|
dest_cmd += ' {0}'.format(level)
|
|
|
|
if level:
|
|
|
|
|
|
|
|
dest_cmd += ' {0}'.format(level)
|
|
|
|
commands.append(dest_cmd)
|
|
|
|
commands.append(dest_cmd)
|
|
|
|
return commands
|
|
|
|
return commands
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -268,6 +275,14 @@ def map_config_to_obj(module):
|
|
|
|
'facility': parse_facility(line, dest),
|
|
|
|
'facility': parse_facility(line, dest),
|
|
|
|
'level': parse_level(line, dest)
|
|
|
|
'level': parse_level(line, dest)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
elif validate_ip_address(match.group(1)):
|
|
|
|
|
|
|
|
dest = 'host'
|
|
|
|
|
|
|
|
obj.append({
|
|
|
|
|
|
|
|
'dest': dest,
|
|
|
|
|
|
|
|
'name': match.group(1),
|
|
|
|
|
|
|
|
'facility': parse_facility(line, dest),
|
|
|
|
|
|
|
|
'level': parse_level(line, dest)
|
|
|
|
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
ip_match = re.search(r'\d+\.\d+\.\d+\.\d+', match.group(1), re.M)
|
|
|
|
ip_match = re.search(r'\d+\.\d+\.\d+\.\d+', match.group(1), re.M)
|
|
|
|
if ip_match:
|
|
|
|
if ip_match:
|
|
|
@ -278,6 +293,7 @@ def map_config_to_obj(module):
|
|
|
|
'facility': parse_facility(line, dest),
|
|
|
|
'facility': parse_facility(line, dest),
|
|
|
|
'level': parse_level(line, dest)
|
|
|
|
'level': parse_level(line, dest)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
return obj
|
|
|
|
return obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -373,6 +389,9 @@ def main():
|
|
|
|
required_if=required_if,
|
|
|
|
required_if=required_if,
|
|
|
|
supports_check_mode=True)
|
|
|
|
supports_check_mode=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
device_info = get_capabilities(module)
|
|
|
|
|
|
|
|
os_version = device_info['device_info']['network_os_version']
|
|
|
|
|
|
|
|
|
|
|
|
warnings = list()
|
|
|
|
warnings = list()
|
|
|
|
check_args(module, warnings)
|
|
|
|
check_args(module, warnings)
|
|
|
|
|
|
|
|
|
|
|
@ -383,7 +402,7 @@ def main():
|
|
|
|
want = map_params_to_obj(module, required_if=required_if)
|
|
|
|
want = map_params_to_obj(module, required_if=required_if)
|
|
|
|
have = map_config_to_obj(module)
|
|
|
|
have = map_config_to_obj(module)
|
|
|
|
|
|
|
|
|
|
|
|
commands = map_obj_to_commands((want, have), module)
|
|
|
|
commands = map_obj_to_commands((want, have), module, os_version)
|
|
|
|
result['commands'] = commands
|
|
|
|
result['commands'] = commands
|
|
|
|
|
|
|
|
|
|
|
|
if commands:
|
|
|
|
if commands:
|
|
|
|