From 1476e30c262930f8a583c00a1a968032514a8e3e Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Tue, 6 Jun 2017 11:45:02 +0200 Subject: [PATCH] Add net_vlan platform agnostic module (#25252) * Add net_vlan platform agnostic module * Add vlan_id param * Fix documentation and examples * Remove whitespace --- lib/ansible/modules/network/net_vlan.py | 84 +++++++++++++++++++++++++ lib/ansible/plugins/action/net_vlan.py | 27 ++++++++ 2 files changed, 111 insertions(+) create mode 100644 lib/ansible/modules/network/net_vlan.py create mode 100644 lib/ansible/plugins/action/net_vlan.py diff --git a/lib/ansible/modules/network/net_vlan.py b/lib/ansible/modules/network/net_vlan.py new file mode 100644 index 0000000000..3ab0061f7b --- /dev/null +++ b/lib/ansible/modules/network/net_vlan.py @@ -0,0 +1,84 @@ +#!/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 . +# + +ANSIBLE_METADATA = {'metadata_version': '1.0', + 'status': ['preview'], + 'supported_by': 'core'} + + +DOCUMENTATION = """ +--- +module: net_vlan +version_added: "2.4" +author: "Ricardo Carrillo Cruz (@rcarrillocruz)" +short_description: Manage VLANs on network devices +description: + - This module provides declarative management of VLANs + on network devices. +options: + name: + description: + - Name of the VLAN. + vlan_id: + description: + - ID of the VLAN. + interfaces: + description: + - List of interfaces the VLAN should be configured on. + collection: + description: List of VLANs definitions + purge: + description: + - Purge VLANs not defined in the collections parameter. + default: no + state: + description: + - State of the VLAN configuration. + default: present + choices: ['present', 'absent', 'active', 'suspend'] +""" + +EXAMPLES = """ +- name: configure VLAN ID and name + net_vlan: + vlan_id: 20 + name: test-vlan + +- name: remove configuration + net_vlan: + state: absent + +- name: configure VLAN state + net_vlan: + vlan_id: + state: suspend + +""" + +RETURN = """ +commands: + description: The list of configuration mode commands to send to the device + returned: always + type: list + sample: + - vlan 20 + - name test-vlan +""" diff --git a/lib/ansible/plugins/action/net_vlan.py b/lib/ansible/plugins/action/net_vlan.py new file mode 100644 index 0000000000..cad73f8a26 --- /dev/null +++ b/lib/ansible/plugins/action/net_vlan.py @@ -0,0 +1,27 @@ +# (c) 2017, Ansible Inc, +# +# 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 . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action.net_base import ActionModule as _ActionModule + + +class ActionModule(_ActionModule): + def run(self, tmp=None, task_vars=None): + result = super(ActionModule, self).run(tmp, task_vars) + + return result