From 7eab15203d6242b1bc56e9a5c5ff0395bc274efb Mon Sep 17 00:00:00 2001 From: przsus <101723670+przsus@users.noreply.github.com> Date: Fri, 13 Dec 2024 08:44:14 +0100 Subject: [PATCH] azure_device_params role --- roles/azure_device_params/README.md | 1 + roles/azure_device_params/meta/main.yml | 17 +++++++ .../tasks/az_cedge_ec2_instance.yml | 42 +++++++++++++++++ roles/azure_device_params/tasks/main.yml | 46 +++++++++++++++++++ 4 files changed, 106 insertions(+) create mode 100644 roles/azure_device_params/README.md create mode 100644 roles/azure_device_params/meta/main.yml create mode 100644 roles/azure_device_params/tasks/az_cedge_ec2_instance.yml create mode 100644 roles/azure_device_params/tasks/main.yml diff --git a/roles/azure_device_params/README.md b/roles/azure_device_params/README.md new file mode 100644 index 0000000..1333ed7 --- /dev/null +++ b/roles/azure_device_params/README.md @@ -0,0 +1 @@ +TODO diff --git a/roles/azure_device_params/meta/main.yml b/roles/azure_device_params/meta/main.yml new file mode 100644 index 0000000..22c5386 --- /dev/null +++ b/roles/azure_device_params/meta/main.yml @@ -0,0 +1,17 @@ +# Copyright 2024 Cisco Systems, Inc. and its affiliates + +--- + +galaxy_info: + author: Przemyslaw Susko + description: Deploy Cisco SD-WAN cEdges (C8000V) on AWS + license: GPL-3.0-or-later + min_ansible_version: "2.16.6" + + galaxy_tags: + - cisco + - sdwan + - catalystwan + - networking + +dependencies: [] diff --git a/roles/azure_device_params/tasks/az_cedge_ec2_instance.yml b/roles/azure_device_params/tasks/az_cedge_ec2_instance.yml new file mode 100644 index 0000000..15b44dc --- /dev/null +++ b/roles/azure_device_params/tasks/az_cedge_ec2_instance.yml @@ -0,0 +1,42 @@ +# 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: Set mgmt and transport IP address facts + ansible.builtin.set_fact: + mgmt_public_ip: "{{ (public_ips | selectattr('tags.type', 'equalto', 'mgmt') | list | first).ip_address }}" + transport_public_ip: "{{ (public_ips | selectattr('tags.type', 'equalto', 'transport') | list | first).ip_address }}" + +- name: Get service NICs + azure.azcollection.azure_rm_networkinterface_info: + resource_group: "{{ az_resource_group }}" + tags: + - type:service + register: service_nic_info + +- name: Set helper facts + ansible.builtin.set_fact: + service_interfaces: [] + last_index: 2 + cedge_service_nic_info: "{{ service_nic_info.networkinterfaces | selectattr('tags.Name', 'search', hostname) | list }}" + +- name: Append to service_interfaces fact + ansible.builtin.set_fact: + service_interfaces: "{{ service_interfaces + [{'addr': item.ip_configurations[0].private_ip_address, 'index': last_index}] }}" + loop: "{{ cedge_service_nic_info }}" + +- name: Set instance fact + ansible.builtin.set_fact: + instance: + hostname: "{{ hostname }}" + admin_username: "admin" + admin_password: "{{ admin_password }}" + mgmt_public_ip: "{{ mgmt_public_ip }}" + transport_public_ip: "{{ transport_public_ip }}" + service_interfaces: "{{ service_interfaces }}" + +- name: Update deployment facts + ansible.builtin.set_fact: + deployment_facts: + deployed_edge_instances: "{{ deployment_facts.deployed_edge_instances + [instance] }}" diff --git a/roles/azure_device_params/tasks/main.yml b/roles/azure_device_params/tasks/main.yml new file mode 100644 index 0000000..a2a6460 --- /dev/null +++ b/roles/azure_device_params/tasks/main.yml @@ -0,0 +1,46 @@ +# 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 if user session with Azure is active + ansible.builtin.include_role: + name: common + tasks_from: az_user_session_probe + +- name: Gather public IP addresses + azure.azcollection.azure_rm_publicipaddress_info: + resource_group: "{{ az_resource_group }}" + register: public_ip_info + +- name: Set manager authentication fact + ansible.builtin.set_fact: + manager_authentication: + url: "{{ public_ip_info.publicipaddresses | + selectattr('tags.Machine', 'search', 'vManage') | + selectattr('tags.type', 'equalto', 'mgmt') | + map(attribute='ip_address') | + list | first }}" + username: "admin" + password: "{{ admin_password }}" + +- name: Get all VMs + azure.azcollection.azure_rm_virtualmachine_info: + resource_group: "{{ az_resource_group }}" + register: vm_info + +- name: Filter cedge VMs + ansible.builtin.set_fact: + cedge_vms: "{{ vm_info.vms | selectattr('name', 'search', 'cedge') | list }}" + +- name: Define deployment facts + ansible.builtin.set_fact: + deployment_facts: + deployed_edge_instances: [] + +- name: Get params for cEdge + ansible.builtin.include_tasks: az_cedge_ec2_instance.yml + vars: + hostname: "{{ item.name }}" + public_ips: "{{ public_ip_info.publicipaddresses | selectattr('tags.Machine', 'equalto', item.name) | list }}" + loop: "{{ cedge_vms }}"