community.general/lib/ansible/modules/network/nxos/nxos_igmp.py

170 lines
4.9 KiB
Python
Raw Normal View History

2016-09-03 01:42:24 +00:00
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
2017-08-16 03:16:38 +00:00
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
2016-12-06 10:35:05 +00:00
2016-09-03 01:42:24 +00:00
DOCUMENTATION = '''
---
module: nxos_igmp
extends_documentation_fragment: nxos
2016-09-03 01:42:24 +00:00
version_added: "2.2"
short_description: Manages IGMP global configuration.
2016-09-03 01:42:24 +00:00
description:
- Manages IGMP global configuration configuration settings.
2016-09-03 01:42:24 +00:00
author:
- Jason Edelman (@jedelman8)
- Gabriele Gerbino (@GGabriele)
notes:
- Tested against NXOSv 7.3.(0)D1(1) on VIRL
- When C(state=default), all supported params will be reset to a
default state.
2016-09-03 01:42:24 +00:00
- If restart is set to true with other params set, the restart will happen
last, i.e. after the configuration takes place.
2016-09-03 01:42:24 +00:00
options:
flush_routes:
description:
- Removes routes when the IGMP process is restarted. By default,
routes are not flushed.
required: false
default: null
choices: ['true', 'false']
enforce_rtr_alert:
description:
- Enables or disables the enforce router alert option check for
IGMPv2 and IGMPv3 packets.
2016-09-03 01:42:24 +00:00
required: false
default: null
choices: ['true', 'false']
restart:
description:
- Restarts the igmp process (using an exec config command).
2016-09-03 01:42:24 +00:00
required: false
default: null
choices: ['true', 'false']
state:
description:
- Manages desired state of the resource.
2016-09-03 01:42:24 +00:00
required: false
default: present
choices: ['present', 'default']
'''
EXAMPLES = '''
Examples syntax batch7 (#5624) * Change example syntax on nxos_feature module * Change example syntax on nxos_hsrp module * Change example syntax on nxos_igmp module * Change example syntax on nxos_interface module * Change example syntax on nxos_interface_ospf module * Change example syntax on nxos_ip_interface module * Change example syntax on nxos_ping module * Change example syntax on nxos_switchport module * Change example syntax on nxos_vlan module * Change example syntax on nxos_vrf module * Change example syntax on nxos_vrf_interface module * Change example syntax on nxos_vrrp module * Change example syntax on meta module * Change example syntax on set_fact module * Change example syntax on win_copy module * Change example syntax on win_file module * Change example syntax on win_get_url module Remove escaping of \ characeter in Windows paths since it's no longer required for single quoted or unquoted values when using multi-line YAML syntax. * Change example syntax on win_lineinfile module * Change example syntax on win_msi module * Change example syntax on win_stat module * Remove nxos_bgp example from nxos_igmp module * Mark examples as regexp to avoid syntax error * Cleanup win_copy.py examples * Cleanup win_file.py examples * Remove quotes in win_get_url.py examples * Cleanup quotes and languare in win_lineinfile.py * Cleanup examples in win_group.py * Cleanup examples in win_service.py * Don't use : in documentation because it breaks the YAML syntax check * Cleanup win_copy.py examples * Cleanup win_copy.py examples * Minor change to fix test failure * Use single quotes
2016-11-22 16:07:21 +00:00
- name: Default igmp global params (all params except restart)
nxos_igmp:
state: default
host: "{{ inventory_hostname }}"
2016-09-03 01:42:24 +00:00
Examples syntax batch7 (#5624) * Change example syntax on nxos_feature module * Change example syntax on nxos_hsrp module * Change example syntax on nxos_igmp module * Change example syntax on nxos_interface module * Change example syntax on nxos_interface_ospf module * Change example syntax on nxos_ip_interface module * Change example syntax on nxos_ping module * Change example syntax on nxos_switchport module * Change example syntax on nxos_vlan module * Change example syntax on nxos_vrf module * Change example syntax on nxos_vrf_interface module * Change example syntax on nxos_vrrp module * Change example syntax on meta module * Change example syntax on set_fact module * Change example syntax on win_copy module * Change example syntax on win_file module * Change example syntax on win_get_url module Remove escaping of \ characeter in Windows paths since it's no longer required for single quoted or unquoted values when using multi-line YAML syntax. * Change example syntax on win_lineinfile module * Change example syntax on win_msi module * Change example syntax on win_stat module * Remove nxos_bgp example from nxos_igmp module * Mark examples as regexp to avoid syntax error * Cleanup win_copy.py examples * Cleanup win_file.py examples * Remove quotes in win_get_url.py examples * Cleanup quotes and languare in win_lineinfile.py * Cleanup examples in win_group.py * Cleanup examples in win_service.py * Don't use : in documentation because it breaks the YAML syntax check * Cleanup win_copy.py examples * Cleanup win_copy.py examples * Minor change to fix test failure * Use single quotes
2016-11-22 16:07:21 +00:00
- name: Ensure the following igmp global config exists on the device
nxos_igmp:
flush_routes: true
enforce_rtr_alert: true
host: "{{ inventory_hostname }}"
- name: Restart the igmp process
nxos_igmp:
restart: true
host: "{{ inventory_hostname }}"
2016-09-03 01:42:24 +00:00
'''
RETURN = '''
updates:
description: commands sent to the device
returned: always
type: list
sample: ["ip igmp flush-routes"]
'''
from ansible.module_utils.nxos import load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
2016-09-03 01:42:24 +00:00
def get_current(module):
output = run_commands(module, {'command': 'show running-config', 'output': 'text'})
return {
'flush_routes': 'ip igmp flush-routes' in output[0],
'enforce_rtr_alert': 'ip igmp enforce-router-alert' in output[0]
}
2016-09-03 01:42:24 +00:00
def get_desired(module):
return {
'flush_routes': module.params['flush_routes'],
'enforce_rtr_alert': module.params['enforce_rtr_alert']
}
2016-09-03 01:42:24 +00:00
def main():
argument_spec = dict(
flush_routes=dict(type='bool'),
enforce_rtr_alert=dict(type='bool'),
restart=dict(type='bool', default=False),
state=dict(choices=['present', 'default'], default='present'),
include_defaults=dict(default=False),
config=dict(),
save=dict(type='bool', default=False)
2016-09-03 01:42:24 +00:00
)
argument_spec.update(nxos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
2016-09-03 01:42:24 +00:00
warnings = list()
check_args(module, warnings)
current = get_current(module)
desired = get_desired(module)
2016-09-03 01:42:24 +00:00
state = module.params['state']
restart = module.params['restart']
commands = list()
2016-09-03 01:42:24 +00:00
if state == 'default':
if current['flush_routes']:
commands.append('no ip igmp flush-routes')
if current['enforce_rtr_alert']:
commands.append('no ip igmp enforce-router-alert')
2016-09-03 01:42:24 +00:00
elif state == 'present':
if desired['flush_routes'] and not current['flush_routes']:
commands.append('ip igmp flush-routes')
if desired['enforce_rtr_alert'] and not current['enforce_rtr_alert']:
commands.append('ip igmp enforce-router-alert')
2016-09-03 01:42:24 +00:00
result = {'changed': False, 'updates': commands, 'warnings': warnings}
2016-09-03 01:42:24 +00:00
if commands:
if not module.check_mode:
load_config(module, commands)
result['changed'] = True
2016-09-03 01:42:24 +00:00
if module.params['restart']:
run_commands(module, 'restart igmp')
2016-09-03 01:42:24 +00:00
module.exit_json(**result)
if __name__ == '__main__':
main()