From 0cd9fb77679a500541635ccbbd17b1a993cd7947 Mon Sep 17 00:00:00 2001 From: Karl Newell Date: Wed, 16 Jan 2019 15:06:08 -0500 Subject: [PATCH] Update playbooks to deploy vmx and switches on esxi --- .gitignore | 2 + core/core-model-sr.yml | 13 ++++- core/core-to-nodes.j2 | 8 +++ core_config/sr-vmx1-config.txt | 1 - core_config/sr-vmx2-config.txt | 1 - core_config/sr-vmx3-config.txt | 1 - core_config/sr-vmx4-config.txt | 1 - core_config/sr-vmx5-config.txt | 48 +++++++++++------ core_config/sr-vmx6-config.txt | 1 - core_config/sr-vmx7-config.txt | 48 +++++++++++------ core_config/sr-vmx8-config.txt | 1 - core_config/sr-vmx9-config.txt | 1 - hosts_vmware | 12 +++++ junos/core.j2 | 20 ++++++- lab_deploy.yml | 95 ++++++++++++++++++++++++++++++++++ nodes.yml | 17 +++++- ova_deploy.yml | 35 +++++++++++++ switch_deploy.yml | 30 +++++++++++ vm_deploy.yml | 39 ++++++++++++++ vm_destroy.yml | 31 +++++++++++ 20 files changed, 363 insertions(+), 42 deletions(-) create mode 100644 hosts_vmware create mode 100644 lab_deploy.yml create mode 100644 ova_deploy.yml create mode 100644 switch_deploy.yml create mode 100644 vm_deploy.yml create mode 100755 vm_destroy.yml diff --git a/.gitignore b/.gitignore index 5471ccc..e2e936f 100644 --- a/.gitignore +++ b/.gitignore @@ -104,3 +104,5 @@ pip-selfcheck.json *.swp .retry +group_vars/vmware +*.ova diff --git a/core/core-model-sr.yml b/core/core-model-sr.yml index b607082..f0430b7 100644 --- a/core/core-model-sr.yml +++ b/core/core-model-sr.yml @@ -58,6 +58,15 @@ nodes: sid: 90 iso: 49.0001.0010.0100.1009.00 +lags: + - node: sr-vmx5 + intf: ae0 + ports: [ge-0/0/2, ge-0/0/3] + - node: sr-vmx7 + intf: ae0 + ports: [ge-0/0/2, ge-0/0/3] + + links: - {left: sr-vmx1, left_port: ge-0/0/0, left_ip: 10.0.0.0.0, right: sr-vmx2, right_port: ge-0/0/0, right_ip: 10.0.0.0.1, @@ -91,8 +100,8 @@ links: right: sr-vmx6, right_port: ge-0/0/3, right_ip: 10.0.0.11, mask: 31, cost: 1000, mpls: True, iso: True } - - {left: sr-vmx5, left_port: ge-0/0/2, left_ip: 10.0.0.12, - right: sr-vmx7, right_port: ge-0/0/2, right_ip: 10.0.0.13, + - {left: sr-vmx5, left_port: ae0, left_ip: 10.0.0.12, + right: sr-vmx7, right_port: ae0, right_ip: 10.0.0.13, mask: 31, cost: 500, mpls: True, iso: True } - {left: sr-vmx6, left_port: ge-0/0/0, left_ip: 10.0.0.14, diff --git a/core/core-to-nodes.j2 b/core/core-to-nodes.j2 index b57c0bf..3e003bb 100644 --- a/core/core-to-nodes.j2 +++ b/core/core-to-nodes.j2 @@ -21,6 +21,14 @@ nodes: {% if node.iso is defined %} iso: {{ node.iso }} {% endif %} + lags: +{% for lag in lags %} +{% if lag.node == node.name %} +{% for port in lag.ports %} + {{ port }}: {{ lag.intf }} +{% endfor %} +{% endif %} +{% endfor %} links: {% for link in links %} {% if link.left == node.name %} diff --git a/core_config/sr-vmx1-config.txt b/core_config/sr-vmx1-config.txt index b128079..fa8cdca 100644 --- a/core_config/sr-vmx1-config.txt +++ b/core_config/sr-vmx1-config.txt @@ -39,7 +39,6 @@ system { } } } - interfaces { ge-0/0/0 { description "sr-vmx2" diff --git a/core_config/sr-vmx2-config.txt b/core_config/sr-vmx2-config.txt index ba8bc4c..c607cf2 100644 --- a/core_config/sr-vmx2-config.txt +++ b/core_config/sr-vmx2-config.txt @@ -39,7 +39,6 @@ system { } } } - interfaces { ge-0/0/0 { description "sr-vmx1" diff --git a/core_config/sr-vmx3-config.txt b/core_config/sr-vmx3-config.txt index 06b7aa3..bda6420 100644 --- a/core_config/sr-vmx3-config.txt +++ b/core_config/sr-vmx3-config.txt @@ -39,7 +39,6 @@ system { } } } - interfaces { ge-0/0/2 { description "sr-vmx1" diff --git a/core_config/sr-vmx4-config.txt b/core_config/sr-vmx4-config.txt index b0e0d75..d80830a 100644 --- a/core_config/sr-vmx4-config.txt +++ b/core_config/sr-vmx4-config.txt @@ -39,7 +39,6 @@ system { } } } - interfaces { ge-0/0/0 { description "sr-vmx5" diff --git a/core_config/sr-vmx5-config.txt b/core_config/sr-vmx5-config.txt index c06abd2..9d78974 100644 --- a/core_config/sr-vmx5-config.txt +++ b/core_config/sr-vmx5-config.txt @@ -39,8 +39,25 @@ system { } } } - +chassis { + aggregated-devices { + ethernet { + device-count 10; + } + } +} interfaces { + ae0 { + description "sr-vmx7" + unit 0 { + family inet { + address 10.0.0.12/31 + } + family mpls; + family iso; + } + } + ge-0/0/0 { description "sr-vmx4" unit 0 { @@ -64,16 +81,17 @@ interfaces { } ge-0/0/2 { - description "sr-vmx7" - unit 0 { - family inet { - address 10.0.0.12/31 - } - family mpls; - family iso; + description "[ae0]" + gigether-options { + 802.3.ad ae0 + } + } + ge-0/0/3 { + description "[ae0]" + gigether-options { + 802.3.ad ae0 } } - fxp0 { description "OOB to MGMT Network"; unit 0 { @@ -129,6 +147,10 @@ protocols { } } level 1 disable; + interface ae0.0 { + point-to-point; + metric 500; + } interface ge-0/0/0.0 { point-to-point; metric 1000; @@ -137,23 +159,19 @@ protocols { point-to-point; metric 1000; } - interface ge-0/0/2.0 { - point-to-point; - metric 500; - } interface lo0.0 { passive; } } mpls { + interface ae0.0; interface ge-0/0/0.0; interface ge-0/0/1.0; - interface ge-0/0/2.0; } lldp { + interface ae0; interface ge-0/0/0; interface ge-0/0/1; - interface ge-0/0/2; } } policy-options { diff --git a/core_config/sr-vmx6-config.txt b/core_config/sr-vmx6-config.txt index 178f047..c58db44 100644 --- a/core_config/sr-vmx6-config.txt +++ b/core_config/sr-vmx6-config.txt @@ -39,7 +39,6 @@ system { } } } - interfaces { ge-0/0/0 { description "sr-vmx7" diff --git a/core_config/sr-vmx7-config.txt b/core_config/sr-vmx7-config.txt index 505cb52..52506c9 100644 --- a/core_config/sr-vmx7-config.txt +++ b/core_config/sr-vmx7-config.txt @@ -39,8 +39,25 @@ system { } } } - +chassis { + aggregated-devices { + ethernet { + device-count 10; + } + } +} interfaces { + ae0 { + description "sr-vmx5" + unit 0 { + family inet { + address 10.0.0.13/31 + } + family mpls; + family iso; + } + } + ge-0/0/0 { description "sr-vmx6" unit 0 { @@ -64,16 +81,17 @@ interfaces { } ge-0/0/2 { - description "sr-vmx5" - unit 0 { - family inet { - address 10.0.0.13/31 - } - family mpls; - family iso; + description "[ae0]" + gigether-options { + 802.3.ad ae0 + } + } + ge-0/0/3 { + description "[ae0]" + gigether-options { + 802.3.ad ae0 } } - fxp0 { description "OOB to MGMT Network"; unit 0 { @@ -131,6 +149,10 @@ protocols { } } level 1 disable; + interface ae0.0 { + point-to-point; + metric 500; + } interface ge-0/0/0.0 { point-to-point; metric 1000; @@ -139,22 +161,18 @@ protocols { point-to-point; metric 1000; } - interface ge-0/0/2.0 { - point-to-point; - metric 500; - } interface lo0.0 { passive; } } mpls { + interface ae0.0; interface ge-0/0/0.0; interface ge-0/0/1.0; - interface ge-0/0/2.0; } lldp { + interface ae0; interface ge-0/0/0; interface ge-0/0/1; - interface ge-0/0/2; } } diff --git a/core_config/sr-vmx8-config.txt b/core_config/sr-vmx8-config.txt index 7dfa091..f95cc77 100644 --- a/core_config/sr-vmx8-config.txt +++ b/core_config/sr-vmx8-config.txt @@ -39,7 +39,6 @@ system { } } } - interfaces { ge-0/0/0 { description "sr-vmx9" diff --git a/core_config/sr-vmx9-config.txt b/core_config/sr-vmx9-config.txt index 4f34dee..18b8ffe 100644 --- a/core_config/sr-vmx9-config.txt +++ b/core_config/sr-vmx9-config.txt @@ -39,7 +39,6 @@ system { } } } - interfaces { ge-0/0/0 { description "sr-vmx8" diff --git a/hosts_vmware b/hosts_vmware new file mode 100644 index 0000000..ad7eb34 --- /dev/null +++ b/hosts_vmware @@ -0,0 +1,12 @@ +[switches] +test-vmx1-br-int +test-vmx2-br-int +test-vmx1-vmx2 + +[vmx] +test-vmx1 +test-vmx2 + +[vmware:children] +switches +vmx diff --git a/junos/core.j2 b/junos/core.j2 index 17d2aec..0483389 100644 --- a/junos/core.j2 +++ b/junos/core.j2 @@ -45,7 +45,15 @@ system { } } } - +{% if node.lags %} +chassis { + aggregated-devices { + ethernet { + device-count 10; + } + } +} +{% endif %} {# ************************************************** ### Interfaces configuration ###### @@ -83,6 +91,16 @@ interfaces { } {% endif %} {% endfor %} +{% if node.lags %} +{% for intf,lag in node.lags.items()|sort %} + {{ intf.split('.')[0] }} { + description "[{{ lag }}]" + gigether-options { + 802.3.ad {{ lag }} + } + } +{% endfor %} +{% endif %} fxp0 { description "OOB to MGMT Network"; unit 0 { diff --git a/lab_deploy.yml b/lab_deploy.yml new file mode 100644 index 0000000..5089adf --- /dev/null +++ b/lab_deploy.yml @@ -0,0 +1,95 @@ +--- +- name: Create a vswitch + hosts: switches + tags: switch + gather_facts: no + tasks: + - name: Create the vswitch + vmware_vswitch: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + esxi_hostname: "{{ esxi_hostname }}" + validate_certs: False + switch_name: "{{ inventory_hostname }}" + mtu: 9000 + delegate_to: localhost + - name: Create the portgroup + vmware_portgroup: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + esxi_hostname: "{{ esxi_hostname }}" + validate_certs: False + switch_name: "{{ inventory_hostname }}" + portgroup_name: "{{ inventory_hostname }}" + network_policy: + promiscuous_mode: true + forged_transmits: true + mac_changes: true + vlan_id: 0 + delegate_to: localhost + +- name: Deploy an ova + hosts: vmx + tags: ova + gather_facts: no + tasks: + - name: Deploy the vcp ova + vmware_deploy_ovf: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: False + allow_duplicates: no + name: "{{ inventory_hostname }}-vcp" + datastore: datastore2 + ova: ova/vcp_17.3R3.10.ova + disk_provisioning: thin + power_on: no + networks: + br-ext: NS-DEV-NAT + br-int: "{{ inventory_hostname }}-br-int" + delegate_to: localhost + - name: Deploy the vfpc ova + vmware_deploy_ovf: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: False + allow_duplicates: no + name: "{{ inventory_hostname }}-vfpc" + datastore: datastore2 + ova: ova/vfpc_17.3R3.10.ova + disk_provisioning: thin + power_on: no + networks: + br-ext: NS-DEV-NAT + br-int: "{{ inventory_hostname }}-br-int" + delegate_to: localhost + +- name: Update vmx networking + hosts: vmx + tags: update_network + gather_facts: no + tasks: + - name: Update vmx networking + vmware_guest: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + esxi_hostname: "{{ esxi_hostname }}" + validate_certs: False + name: "{{ inventory_hostname }}-vfpc" + folder: / + datastore: datastore2 + networks: + - name: NS-DEV-NAT + - name: "{{ inventory_hostname }}-br-int" + - name: "test-vmx1-vmx2" + device_type: vmxnet3 + hardware: + num_cpus: 3 + memory_mb: 8192 + state: present + delegate_to: localhost diff --git a/nodes.yml b/nodes.yml index 219ce95..ed3706a 100644 --- a/nodes.yml +++ b/nodes.yml @@ -14,6 +14,7 @@ nodes: rid: 192.168.0.1 sid: 10 iso: 49.0001.0010.0100.1001.00 + lags: links: ge-0/0/0.0: { ip: 10.0.0.0.0, remote: sr-vmx2, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/1.0: { ip: 10.0.0.2, remote: sr-vmx4, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} @@ -32,6 +33,7 @@ nodes: rid: 192.168.0.2 sid: 20 iso: 49.0001.0010.0100.1002.00 + lags: links: ge-0/0/0.0: { ip: 10.0.0.0.1, remote: sr-vmx1, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/1.0: { ip: 10.0.0.4, remote: sr-vmx5, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} @@ -49,6 +51,7 @@ nodes: rid: 192.168.0.3 sid: 30 iso: 49.0001.0010.0100.1003.00 + lags: links: ge-0/0/2.0: { ip: 10.0.0.23, remote: sr-vmx1, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/4.0: { ip: 10.0.0.24, remote: sr-vmx6, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} @@ -66,6 +69,7 @@ nodes: rid: 192.168.0.4 sid: 40 iso: 49.0001.0010.0100.1004.00 + lags: links: ge-0/0/1.0: { ip: 10.0.0.3, remote: sr-vmx1, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/0.0: { ip: 10.0.0.6, remote: sr-vmx5, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} @@ -88,10 +92,13 @@ nodes: rid: 192.168.0.5 sid: 50 iso: 49.0001.0010.0100.1005.00 + lags: + ge-0/0/2: ae0 + ge-0/0/3: ae0 links: ge-0/0/1.0: { ip: 10.0.0.5, remote: sr-vmx2, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/0.0: { ip: 10.0.0.7, remote: sr-vmx4, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} - ge-0/0/2.0: { ip: 10.0.0.12, remote: sr-vmx7, mask: 31, cost: 500, vlan: 0, mpls: True, iso: True} + ae0.0: { ip: 10.0.0.12, remote: sr-vmx7, mask: 31, cost: 500, vlan: 0, mpls: True, iso: True} bgp: ibgp: peers: @@ -106,6 +113,7 @@ nodes: rid: 192.168.0.6 sid: 60 iso: 49.0001.0010.0100.1006.00 + lags: links: ge-0/0/4.0: { ip: 10.0.0.25, remote: sr-vmx3, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/2.0: { ip: 10.0.0.9, remote: sr-vmx4, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} @@ -126,8 +134,11 @@ nodes: rid: 192.168.0.7 sid: 70 iso: 49.0001.0010.0100.1007.00 + lags: + ge-0/0/2: ae0 + ge-0/0/3: ae0 links: - ge-0/0/2.0: { ip: 10.0.0.13, remote: sr-vmx5, mask: 31, cost: 500, vlan: 0, mpls: True, iso: True} + ae0.0: { ip: 10.0.0.13, remote: sr-vmx5, mask: 31, cost: 500, vlan: 0, mpls: True, iso: True} ge-0/0/0.0: { ip: 10.0.0.15, remote: sr-vmx6, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/1.0: { ip: 10.0.0.18, remote: sr-vmx9, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} bgp: @@ -147,6 +158,7 @@ nodes: rid: 192.168.0.8 sid: 80 iso: 49.0001.0010.0100.1008.00 + lags: links: ge-0/0/1.0: { ip: 10.0.0.17, remote: sr-vmx6, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/0.0: { ip: 10.0.0.20, remote: sr-vmx9, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} @@ -164,6 +176,7 @@ nodes: rid: 192.168.0.9 sid: 90 iso: 49.0001.0010.0100.1009.00 + lags: links: ge-0/0/1.0: { ip: 10.0.0.19, remote: sr-vmx7, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} ge-0/0/0.0: { ip: 10.0.0.21, remote: sr-vmx8, mask: 31, cost: 1000, vlan: 0, mpls: True, iso: True} diff --git a/ova_deploy.yml b/ova_deploy.yml new file mode 100644 index 0000000..d3ebdc4 --- /dev/null +++ b/ova_deploy.yml @@ -0,0 +1,35 @@ +--- +- name: Deploy an ova + hosts: vmware + gather_facts: no + tasks: + - name: Deploy the vcp ova + vmware_deploy_ovf: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: False + name: testvmx2_vcp + datastore: datastore2 + ova: ova/vcp_17.3R3.10.ova + disk_provisioning: thin + power_on: no + networks: + br-ext: NS-DEV-NAT + br-int: testvmx2-br-int + delegate_to: localhost + - name: Deploy the vfpc ova + vmware_deploy_ovf: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + validate_certs: False + name: testvmx2_vfpc + datastore: datastore2 + ova: ova/vfpc_17.3R3.10.ova + disk_provisioning: thin + power_on: no + networks: + br-ext: NS-DEV-NAT + br-int: testvmx2-br-int + delegate_to: localhost diff --git a/switch_deploy.yml b/switch_deploy.yml new file mode 100644 index 0000000..5004d5a --- /dev/null +++ b/switch_deploy.yml @@ -0,0 +1,30 @@ +--- +- name: Create a vswitch + hosts: vmware + gather_facts: no + tasks: + - name: Create the vswitch + vmware_vswitch: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + esxi_hostname: "{{ esxi_hostname }}" + validate_certs: False + switch_name: testvmx2-br-int + mtu: 9000 + delegate_to: localhost + - name: Create the vswitch + vmware_portgroup: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + esxi_hostname: "{{ esxi_hostname }}" + validate_certs: False + switch_name: testvmx2-br-int + portgroup_name: testvmx2-br-int + network_policy: + promiscuous_mode: true + forged_transmits: true + mac_changes: true + vlan_id: 0 + delegate_to: localhost diff --git a/vm_deploy.yml b/vm_deploy.yml new file mode 100644 index 0000000..7e2499c --- /dev/null +++ b/vm_deploy.yml @@ -0,0 +1,39 @@ +--- +- name: Create a VM from a template + hosts: vmware + gather_facts: no + tasks: + - name: Clone the template + vmware_guest: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + esxi_hostname: "{{ esxi_hostname }}" + validate_certs: False + name: testvmx1_vfpc +# template: islet + folder: / + networks: + - name: NS-DEV-NAT + - name: testvmx-br-int + - name: srlab-vmx9-br-int + device_type: vmxnet3 + - name: srlab-vmx8-br-int + device_type: vmxnet3 + hardware: + num_cpus: 3 + memory_mb: 8192 + state: present +# guest_id: ubuntu64Guest +# disk: +# - size_gb: 10 +# type: thin +# datastore: datastore2 +# hardware: +# memory_mb: 512 +# num_cpus: 1 +# scsi: paravirtual +# datacenter: "{{ datacenter_name }}" +# cluster: "{{ cluster_name }}" +# wait_for_ip_address: yes + delegate_to: localhost diff --git a/vm_destroy.yml b/vm_destroy.yml new file mode 100755 index 0000000..eece790 --- /dev/null +++ b/vm_destroy.yml @@ -0,0 +1,31 @@ +#!/usr/bin/env ansible-playbook +--- +- name: Create a VM from a template + hosts: vmware + gather_facts: no + tasks: + - name: Clone the template + vmware_guest: + hostname: "{{ vcenter_hostname }}" + username: "{{ vcenter_username }}" + password: "{{ vcenter_password }}" + esxi_hostname: "{{ esxi_hostname }}" + validate_certs: False + name: testvm_2 +# template: islet + folder: / + state: absent + force: yes +# guest_id: ubuntu64Guest +# disk: +# - size_gb: 10 +# type: thin +# datastore: datastore2 +# hardware: +# memory_mb: 512 +# num_cpus: 1 +# scsi: paravirtual +# datacenter: "{{ datacenter_name }}" +# cluster: "{{ cluster_name }}" +# wait_for_ip_address: yes + delegate_to: localhost