|
| 1 | +# Copyright 2024 Cisco Systems, Inc. and its affiliates |
| 2 | +# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 3 | + |
| 4 | +--- |
| 5 | + |
| 6 | +- name: "Set vpn0_default_gateway fact from VPN 0 subnet value" |
| 7 | + ansible.builtin.set_fact: |
| 8 | + vpn0_default_gateway: "{{ vpn0_subnet | ansible.utils.ipaddr('1') | ansible.utils.ipaddr('address') }}" |
| 9 | + vpn512_default_gateway: "{{ vpn512_subnet | ansible.utils.ipaddr('1') | ansible.utils.ipaddr('address') }}" |
| 10 | + vars: |
| 11 | + vpn0_subnet: "{{ az_subnets | json_query('[?VPN==`0` && type!=`cluster`].cidr | [0]') }}" |
| 12 | + vpn512_subnet: "{{ az_subnets | json_query('[?VPN==`512` && type!=`cluster`].cidr | [0]') }}" |
| 13 | + |
| 14 | +- name: "Get info about NSG: {{ az_network_security_group }}" |
| 15 | + azure.azcollection.azure_rm_securitygroup_info: |
| 16 | + resource_group: "{{ az_resource_group }}" |
| 17 | + name: "{{ az_network_security_group }}" |
| 18 | + register: az_res_gr |
| 19 | + |
| 20 | +- name: "Template userdata file for cedge: {{ hostname }}" |
| 21 | + ansible.builtin.template: |
| 22 | + src: ./userdata_cedge.j2 # ./bond.j2 ./userdata_cedge.j2 |
| 23 | + dest: "{{ userdata_cedge_path }}-{{ hostname }}" |
| 24 | + mode: "0644" |
| 25 | + vars: |
| 26 | + hostname: "{{ instance_item.hostname | replace('_', '-') }}" |
| 27 | + uuid: "{{ instance_item.uuid }}" |
| 28 | + otp: "{{ instance_item.otp }}" |
| 29 | + vbond: "{{ instance_item.vbond }}" |
| 30 | + system_ip: "{{ instance_item.system_ip }}" |
| 31 | + site_id: "{{ instance_item.site_id }}" |
| 32 | + loop: "{{ edge_instances }}" |
| 33 | + loop_control: |
| 34 | + loop_var: instance_item |
| 35 | + when: instance_item.hostname not in instances_info or not instances_info[instance_item.hostname] |
| 36 | + |
| 37 | +- name: Create Azure Deployment |
| 38 | + azure_rm_deployment: |
| 39 | + resource_group: "{{ az_resource_group }}" |
| 40 | + name: "{{ az_resources_prefix }}-edges" |
| 41 | + location: "{{ az_location }}" |
| 42 | + wait_for_deployment_completion: true |
| 43 | + template: |
| 44 | + $schema: "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#" |
| 45 | + contentVersion: "1.0.0.0" |
| 46 | + resources: "{{ lookup('template', 'deployment_resources.j2') }}" |
| 47 | + outputs: "{{ lookup('template', 'deployment_outputs.j2') }}" |
| 48 | + register: azure_deployment |
| 49 | + |
| 50 | +- name: "Extend Network Security Group for machine, NSG: {{ az_network_security_group }}" |
| 51 | + azure.azcollection.azure_rm_securitygroup: |
| 52 | + resource_group: "{{ az_resource_group }}" |
| 53 | + name: "{{ az_network_security_group }}" |
| 54 | + rules: "{{ lookup('template', 'nsg_rules.j2') }}" |
| 55 | + tags: |
| 56 | + Name: "{{ az_network_security_group }}" |
| 57 | + Creator: "{{ az_tag_creator }}" |
| 58 | + Organization: "{{ organization_name }}" |
| 59 | + vars: |
| 60 | + deployed_ips: "{{ azure_deployment['deployment']['outputs']['public_ip_addresses']['value'] | map(attribute='ip') }}" |
| 61 | + existing_nsgs: "{{ az_res_gr.securitygroups | map(attribute='rules') | flatten | map(attribute='source_address_prefix') | list }}" |
| 62 | + when: deployed_ips | difference(existing_nsgs) |
| 63 | + |
| 64 | +- name: Update deployment facts - cedge - that will be consumed by vManage-client in Ansible |
| 65 | + ansible.builtin.set_fact: |
| 66 | + deployment_facts: |
| 67 | + deployed_edge_instances: "{{ deployment_facts.deployed_edge_instances + [instance] }}" |
| 68 | + vars: |
| 69 | + instance: |
| 70 | + hostname: "{{ instance_item['hostname'] }}" |
| 71 | + system_ip: "{{ instance_item['system_ip'] }}" |
| 72 | + admin_username: "{{ admin_username }}" |
| 73 | + admin_password: "{{ admin_password }}" |
| 74 | + mgmt_public_ip: "{{ all_public_ips | json_query('[?host==`'~instance_item['hostname']~'` && type==`mgmt`].ip | [0]') }}" |
| 75 | + transport_public_ip: "{{ all_public_ips | json_query('[?host==`'~instance_item['hostname']~'` && type==`transport`].ip | [0]') }}" |
| 76 | + service_interfaces: "{{ service_interfaces if 'service' in az_subnets | map(attribute='type') else omit }}" |
| 77 | + uuid: "{{ instance_item['uuid'] }}" |
| 78 | + site_id: "{{ instance_item['site_id'] }}" |
| 79 | + all_public_ips: "{{ azure_deployment['deployment']['outputs']['public_ip_addresses']['value'] }}" |
| 80 | + service_interfaces: "{{ azure_deployment['deployment']['outputs']['service_interfaces']['value'][instance_item['hostname']] }}" |
| 81 | + loop: "{{ edge_instances }}" |
| 82 | + loop_control: |
| 83 | + loop_var: instance_item |
| 84 | + when: instance_item.hostname not in instances_info or not instances_info[instance_item.hostname] |
0 commit comments