mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-24 05:40:23 -07:00
Platform agnostic net_system module (#24953)
* Platform agnostic net_system module Also refactor the action network plugins for better code re-use Still more refactoring to do once the connection plugin work is complete * Replace importlib for imp importlib is not available on 2.6, so we need to stick to imp * Load action plugin via module metadata * Better error message if no implementation is found Now the plugin will show the module name and the network OS in the error message * Fix typo on documentation author line * Fix pep8 issues * Add missing options key on doc string and stringify version * Return None in case module has no metadata * Read module metadata only if it's a python module Check for module suffix, if it's .py then read metadata. Otherwise this fails on non-python modules, like Windows PS for example. * Read metadata variable only if it's a python module Fix referencing a variable before assignment * Add action_handler to validate_modules metadata schema * Pull metadata with plugin_docs get_docstring Using load_source from PluginLoader is troublesome, it is not guaranteed a module may be importable at the controller, e.g. if a module depends on module_utils functions it won't work, because module_utils is not in the sys path. Rather than putting that module dependencies introspection, just use plain parsing like plugin_docs get_docstring does as we only care about reading ANSIBLE_METADATA. * Add platform agnostic group of groups for integration tests This will be the target for platform agnostic integration tests. * Add integration tests for net_system * Switch to action plugin inheritance from metadata driven action handler As the metadata action driven action handler work is being worked on on its standalone proposal+PR, let's just go back to have one action handler per platform agnostic module. Those action plugins will inherit from net_base. * Add blank line to fix pep8 * Add aliases file to net_system integration test This will avoid CI failure * Fix integration tests for net_system * Give more precedence to task network_os over inventory network_os
This commit is contained in:
parent
2ee2c8c1ab
commit
64add28657
20 changed files with 674 additions and 6 deletions
110
lib/ansible/modules/network/net_system.py
Normal file
110
lib/ansible/modules/network/net_system.py
Normal file
|
@ -0,0 +1,110 @@
|
|||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2017, Ansible by Red Hat, inc
|
||||
#
|
||||
# This file is part of Ansible by Red Hat
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||
'status': ['preview'],
|
||||
'supported_by': 'core'}
|
||||
|
||||
|
||||
DOCUMENTATION = """
|
||||
---
|
||||
module: net_system
|
||||
version_added: "2.4"
|
||||
author: "Ricardo Carrillo Cruz (@rcarrillocruz)"
|
||||
short_description: Manage the system attributes on network devices
|
||||
description:
|
||||
- This module provides declarative management of node system attributes
|
||||
on network devices. It provides an option to configure host system
|
||||
parameters or remove those parameters from the device active
|
||||
configuration.
|
||||
options:
|
||||
hostname:
|
||||
description:
|
||||
- Configure the device hostname parameter. This option takes an ASCII string value.
|
||||
domain_name:
|
||||
description:
|
||||
- Configure the IP domain name
|
||||
on the remote device to the provided value. Value
|
||||
should be in the dotted name form and will be
|
||||
appended to the C(hostname) to create a fully-qualified
|
||||
domain name.
|
||||
domain_search:
|
||||
description:
|
||||
- Provides the list of domain suffixes to
|
||||
append to the hostname for the purpose of doing name resolution.
|
||||
This argument accepts a list of names and will be reconciled
|
||||
with the current active configuration on the running node.
|
||||
lookup_source:
|
||||
description:
|
||||
- Provides one or more source
|
||||
interfaces to use for performing DNS lookups. The interface
|
||||
provided in C(lookup_source) must be a valid interface configured
|
||||
on the device.
|
||||
name_servers:
|
||||
description:
|
||||
- List of DNS name servers by IP address to use to perform name resolution
|
||||
lookups. This argument accepts either a list of DNS servers See
|
||||
examples.
|
||||
state:
|
||||
description:
|
||||
- State of the configuration
|
||||
values in the device's current active configuration. When set
|
||||
to I(present), the values should be configured in the device active
|
||||
configuration and when set to I(absent) the values should not be
|
||||
in the device active configuration
|
||||
default: present
|
||||
choices: ['present', 'absent']
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: configure hostname and domain name
|
||||
net_system:
|
||||
hostname: ios01
|
||||
domain_name: test.example.com
|
||||
domain-search:
|
||||
- ansible.com
|
||||
- redhat.com
|
||||
- cisco.com
|
||||
|
||||
- name: remove configuration
|
||||
net_system:
|
||||
state: absent
|
||||
|
||||
- name: configure DNS lookup sources
|
||||
net_system:
|
||||
lookup_source: MgmtEth0/0/CPU0/0
|
||||
|
||||
- name: configure name servers
|
||||
net_system:
|
||||
name_servers:
|
||||
- 8.8.8.8
|
||||
- 8.8.4.4
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
commands:
|
||||
description: The list of configuration mode commands to send to the device
|
||||
returned: always
|
||||
type: list
|
||||
sample:
|
||||
- hostname ios01
|
||||
- ip domain name test.example.com
|
||||
"""
|
Loading…
Add table
Add a link
Reference in a new issue