diff --git a/galaxy.yml b/galaxy.yml index de0bfc2..d4cb27e 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: cisco name: catalystwan -version: 0.3.1 +version: 0.3.2 readme: README.md authors: - Arkadiusz Cichon diff --git a/roles/vmanage_version/README.md b/roles/vmanage_version/README.md new file mode 100644 index 0000000..a1620f0 --- /dev/null +++ b/roles/vmanage_version/README.md @@ -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 diff --git a/roles/vmanage_version/meta/main.yml b/roles/vmanage_version/meta/main.yml new file mode 100644 index 0000000..151463c --- /dev/null +++ b/roles/vmanage_version/meta/main.yml @@ -0,0 +1,15 @@ +--- + +galaxy_info: + author: Przemyslaw Susko + 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: [] diff --git a/roles/vmanage_version/tasks/main.yml b/roles/vmanage_version/tasks/main.yml new file mode 100644 index 0000000..7d66cc1 --- /dev/null +++ b/roles/vmanage_version/tasks/main.yml @@ -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, '<') diff --git a/roles/vmanage_version/tasks/variables_assertion.yml b/roles/vmanage_version/tasks/variables_assertion.yml new file mode 100644 index 0000000..ee369fa --- /dev/null +++ b/roles/vmanage_version/tasks/variables_assertion.yml @@ -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