Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding banner support for os6 #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions roles/os6_banner/LICENSE

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions roles/os6_banner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
Banner role
===========

This role facilitates the configuration of global banner attributes. It specifically enables configuration of login,exec and motd banner for OS6. This role is abstracted for Dell EMC PowerSwitch platforms running Dell EMC OS6.

The Banner role requires an SSH connection for connectivity to a Dell EMC OS6 device. You can use any of the built-in OS connection variables.

Role variables
--------------

- Role is abstracted using the `ansible_network_os` variable that can take `dellemc.os6.os6` as a value
- If `os6_cfg_generate` is set to true, the variable generates the role configuration commands in a file
- Any role variable with a corresponding state variable set to absent negates the configuration of that variable
- Setting an empty value for any variable negates the corresponding configuration
- Variables and values are case-sensitive

**os6_banner keys**

| Key | Type | Description | Support |
|------------|---------------------------|---------------------------------------------------------|-----------------------|
| ``login`` | string | specifiy the login banner to be configured (see ``*.*``) | os6 |
| ``motd`` | string | specifiy the login banner to be configured (see ``*.*``) | os6 |
| ``motd.acknowledge`` | boolean: true,false\* | Defines if the motd banner must be acknowledge | os6 |
| ``exec`` | string | specifiy the login banner to be configured (see ``*.*``) | os6 |
| ``*.state`` | string: present,absent | Deletes the banner if set to absent | os6 |
| ``*.text`` | string | Defines the banner sting | os6 |

> **NOTE**: Asterisk (\*) denotes the default value if none is specified.

Connection variables
********************

Ansible Dell EMC Networking roles require connection information to establish communication with the nodes in your inventory. This information can exist in the Ansible *group_vars* or *host_vars* directories, or inventory or in the playbook itself.

| Key | Required | Choices | Description |
|-------------|----------|------------|-----------------------------------------------------|
| ``ansible_host`` | yes | | Specifies the hostname or address for connecting to the remote device over the specified transport |
| ``ansible_port`` | no | | Specifies the port used to build the connection to the remote device; if value is unspecified, the `ANSIBLE_REMOTE_PORT` option is used; it defaults to 22 |
| ``ansible_ssh_user`` | no | | Specifies the username that authenticates the CLI login for the connection to the remote device; if value is unspecified, the `ANSIBLE_REMOTE_USER` environment variable value is used |
| ``ansible_ssh_pass`` | no | | Specifies the password that authenticates the connection to the remote device. |
| ``ansible_become`` | no | yes, no\* | Instructs the module to enter privileged mode on the remote device before sending any commands; if value is unspecified, the `ANSIBLE_BECOME` environment variable value is used, and the device attempts to execute all commands in non-privileged mode |
| ``ansible_become_method`` | no | enable, sudo\* | Instructs the module to allow the become method to be specified for handling privilege escalation; if value is unspecified, the `ANSIBLE_BECOME_METHOD` environment variable value is used |
| ``ansible_become_pass`` | no | | Specifies the password to use if required to enter privileged mode on the remote device; if ``ansible_become`` is set to no this key is not applicable |
| ``ansible_network_os`` | yes | os6, null\* | Loads the correct terminal and cliconf plugins to communicate with the remote device |

> **NOTE**: Asterisk (\*) denotes the default value if none is specified.

Example playbook
----------------

This example uses the *os6_banner role* to completely set the banner. It creates a *hosts* file with the switch details and corresponding variables. The hosts file should define the `ansible_network_os` variable with corresponding Dell EMC OS6 name.

When `os6_cfg_generate` is set to true, the variable generates the configuration commands as a .part file in *build_dir* path. By default, the variable is set to false. The banner role writes a simple playbook that only references the *os6_banner* role. By including the role, you automatically get access to all of the tasks to configure banner features.

**Sample hosts file**

switch1 ansible_host= <ip_address>

**Sample host_vars/switch1**

hostname: switch1
ansible_become: yes
ansible_become_method: enable
ansible_become_pass: xxxxx
ansible_ssh_user: xxxxx
ansible_ssh_pass: xxxxx
ansible_network_os: dellemc.os6.os6
build_dir: ../temp/temp_os6

os6_banner:
login:
text: |
This is a
Multiline banner
state: present


**Simple playbook to setup banner — switch1.yaml**

- hosts: switch1
roles:
- dellemc.os6.os6_banner

**Run**

ansible-playbook -i hosts switch1.yaml

(c) 2017-2020 Dell Inc. or its subsidiaries. All rights reserved.
2 changes: 2 additions & 0 deletions roles/os6_banner/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# defaults file for os6_banner
2 changes: 2 additions & 0 deletions roles/os6_banner/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for os6_banner
18 changes: 18 additions & 0 deletions roles/os6_banner/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020 Dell Inc.
---
galaxy_info:
author: Dell EMC Networking Engineering
description: The os6_banner role facilitates the configuration of banner attributes in devices running Dell EMC Networking Operating Systems.
company: Dell Inc
license: GPLv3
min_ansible_version: 2.9.6

platforms:
- name: os6

galaxy_tags:
- networking
- dell
- emc
- dellemc
- os6
17 changes: 17 additions & 0 deletions roles/os6_banner/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
# tasks file for os6

- name: "Generating banner configuration for os6"
template:
src: os6_banner.j2
dest: "{{ build_dir }}/banner6_{{ hostname }}.conf.part"
when: (ansible_network_os is defined and ansible_network_os == "dellemc.os6.os6") and ((os6_cfg_generate | default('False')) | bool)
# notify: save config os6
register: generate_output

- name: "Provisioning banner configuration for os6"
dellemc.os6.os6_config:
src: os6_banner.j2
when: (ansible_network_os is defined and ansible_network_os == "dellemc.os6.os6")
# notify: save config os6
register: output
61 changes: 61 additions & 0 deletions roles/os6_banner/templates/os6_banner.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#jinja2: trim_blocks: True,lstrip_blocks: True
{####################################

Purpose:
Configure banner commands for os6 devices

os6_banner:
login:
text: |
This is a
Multiline banner
state: present
exec:
text: exec banner
state: present
motd:
text: motd banner
acknowledge: true
state: present
#####################################}
{% if os6_banner is defined and os6_banner %}
{% if os6_banner.login is defined and os6_banner.login %}
{%- set login_vars = os6_banner.login -%}
{% if login_vars.state is defined and login_vars.state=="absent" -%}
no banner login
{%- else -%}
{% if login_vars.text is defined -%}
banner login "{{ login_vars.text }}"
{% endif %}
{% endif %}
{% endif %}

{% if os6_banner.exec is defined and os6_banner.exec %}
{%- set exec_vars = os6_banner.exec -%}
{% if exec_vars.state is defined and exec_vars.state=="absent" -%}
no banner exec
{%- else -%}
{% if exec_vars.text is defined -%}
banner exec "{{ exec_vars.text }}"
{% endif %}
{% endif %}
{% endif %}

{% if os6_banner.motd is defined and os6_banner.motd %}
{%- set motd_vars = os6_banner.motd -%}
{% if motd_vars.state is defined and motd_vars.state=="absent" -%}
no banner motd
{%- else -%}
{% if motd_vars.text is defined -%}
banner motd "{{ motd_vars.text }}"
{% endif %}

{% if motd_vars.acknowledge is defined and motd_vars.acknowledge==true -%}
banner motd acknowledge
{% else %}
no banner motd acknowledge
{% endif %}
{% endif %}

{% endif %}
{% endif %}
6 changes: 6 additions & 0 deletions roles/os6_banner/tests/inventory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
switch1 ansible_host=100.94.51.40 ansible_network_os="dellemc.os6.os6"
switch2 ansible_host=100.94.52.38 ansible_network_os="dellemc.os6.os6"

[os6switches]
switch1
switch2
18 changes: 18 additions & 0 deletions roles/os6_banner/tests/main.os6.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
# vars file for dellemc.os6.os6_banner,
# below gives a sample configuration
# Sample variables for OS6 device

os6_banner:
login:
text: |
This is a
Multiline banner
state: present
exec:
text: exec banner
state: present
motd:
text: motd banner
acknowledge: true
state: present
5 changes: 5 additions & 0 deletions roles/os6_banner/tests/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: os6switches
connection: network_cli
roles:
- dellemc.os6.os6_banner
2 changes: 2 additions & 0 deletions roles/os6_banner/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for os6_banner