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

Add role for verification if vmanage sw version matches requirements #33

Merged
merged 1 commit into from
Nov 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: cisco
name: catalystwan
version: 0.3.1
version: 0.3.2
readme: README.md
authors:
- Arkadiusz Cichon <[email protected]>
Expand Down
54 changes: 54 additions & 0 deletions roles/vmanage_version/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Ansible Role: vmanage_version

This Ansible role is checks if vManage version matches requirements.

## Role Description

The `vmanage_version` role performs the following tasks:

1. Get software version from vManage.
2. Verify if version matches requirements.

## Requirements

- `cisco.catalystwan` collection installed.
- Access details for the Cisco Manager instance must be provided.

## Dependencies

There are no external role dependencies. Only `cisco.catalystwan` collection is required.

## Role Variables

Variables expected by this role:

- `vmanage_instances`: List of vManage instances containing management IP, admin username, admin password and system IP.
- `min_version_required`: A string representing minimum version of vManage this role expects to succeed.

## Example Playbook

Including an example of how to use your role (with variables passed in as parameters):

```yaml
- hosts: all
gather_facts: no
tasks:
- name: Check if vManage version is equal or greater to 20.13.1
import_role:
name: vmanage_mode
vars:
vmanage_instances:
- mgmt_public_ip: '192.0.2.1'
admin_username: 'admin'
admin_password: 'password'
system_ip: '192.168.101.1'
min_version_required: "20.13.1"
```

## License

"GPL-3.0-only"

## Author Information

This role was created by Przemyslaw Susko <[email protected]>
15 changes: 15 additions & 0 deletions roles/vmanage_version/meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---

galaxy_info:
author: Przemyslaw Susko <[email protected]>
description: Check if vManage version matches requirements.
license: GPL-3.0-or-later
min_ansible_version: "0.3.2"

galaxy_tags:
- cisco
- sdwan
- catalystwan
- networking

dependencies: []
51 changes: 51 additions & 0 deletions roles/vmanage_version/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

---

- name: Verify required variables for selected role
ansible.builtin.include_tasks: variables_assertion.yml

- name: Set facts
ansible.builtin.set_fact:
url: "{{ (vmanage_instances | first).mgmt_public_ip }}"
username: "{{ (vmanage_instances | first).admin_username }}"
password: "{{ (vmanage_instances | first).admin_password }}"
system_ip: "{{ (vmanage_instances | first).system_ip }}"

- name: Authenticate to vManage
ansible.builtin.uri:
url: "https://{{ url }}/j_security_check"
method: POST
body: "j_username={{ username }}&j_password={{ password }}"
body_format: form-urlencoded
validate_certs: false
return_content: true
register: login_response

- name: Check if login was successful
ansible.builtin.fail:
msg: "vManage Login failed. Check your credentials."
when: '"JSESSIONID" not in login_response.cookies'

- name: Get vManage version
ansible.builtin.uri:
url: "https://{{ url }}/dataservice/device/system/info?deviceId={{ system_ip }}"
method: GET
validate_certs: false
headers:
Cookie: "JSESSIONID={{ login_response.cookies.JSESSIONID }}"
return_content: true
status_code: 200
register: version_response
when: '"JSESSIONID" in login_response.cookies'

- name: Set vManage version fact
ansible.builtin.set_fact:
vmanage_version: "{{ version_response.json.data[0].version }}"
when: version_response is defined

- name: Ensure vManage version is greater than or equal to specified version
ansible.builtin.fail:
msg: "vManage software version {{ vmanage_version }} is lower than the required version {{ min_version_required }}."
when: vmanage_version is version(min_version_required, '<')
21 changes: 21 additions & 0 deletions roles/vmanage_version/tasks/variables_assertion.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 Cisco Systems, Inc. and its affiliates
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

---

- name: Assert that required variables are provided
ansible.builtin.assert:
that:
- required_var
- required_var is defined
- required_var != None
- required_var != "None"
- required_var != ""
- required_var | length > 0
fail_msg: "Your SD-WAN initial config file missing required variable: {{ required_var }}"
quiet: true
loop:
- "{{ vmanage_instances }}"
- "{{ min_version_required }}"
loop_control:
loop_var: required_var