Table of contents
Virtual network
Create virtual network
-
$aksresourceGroup = "rg-aks-bootstrap-networking-spoke" $vnetAddressprefix = "10.240.0.0/16" $vnetName = "vnet-spoke" az network vnet create ` --name $vnetName ` --resource-group $aksresourceGroup ` --address-prefixes $vnetAddressprefix
-
- name: Create virtual network azure.azcollection.azure_rm_virtualnetwork: resource_group: '{{ _virtual_network.resource_group }}' name: '{{ _virtual_network.name }}' address_prefixes: '{{ _virtual_network.address_prefixes }}' tags: '{{ _virtual_network.tags | default(omit) }}' state: '{{ _virtual_network.state | default("present") }}' vars: _virtual_network: resource_group: "rg-aks-bootstrap-networking-spoke" name: "vnet-spoke" address_prefixes: "10.240.0.0/16"
Get virtual network info
-
Source : https://learn.microsoft.com/en-us/cli/azure/network/vnet?view=azure-cli-latest#az-network-vnet-show
$aksresourceGroup = "rg-aks-bootstrap-networking-spoke" $vnetName = "vnet-spoke" az network vnet show -g $aksresourceGroup -n $vnetName --query "id" -o tsv
-
- name: Get Virtual Network info azure.azcollection.azure_rm_virtualnetwork_info: resource_group: '{{ _virtual_network.resource_group }}' name: '{{ _virtual_network.name }}' register: __virtual_network_info vars: _virtual_network: resource_group: "rg-aks-bootstrap-networking-spoke" name: "vnet-spoke"
Create virtual network peering
-
Command error
Unable to create peering with az cli !!!
$aksresourceGroup = "rg-aks-bootstrap-networking-spoke" $vnetName = "vnet-spoke" $vnetHubName = "vnet-hub" $hubResourceGroup = "rg-francecentral-networking-hub" az network vnet peering create --name np-to-vnet-hub --vnet-name $vnetName --remote-vnet $vnetHubName --resource-group $aksresourceGroup --allow-vnet-access --allow-forwarded-traffic
-
- name: Create virtual network_peering azure.azcollection.azure_rm_virtualnetworkpeering: name: 'np-to-{{ _virtual_network_peering.target.name }}' resource_group: '{{ _virtual_network_peering.source.resource_group }}' virtual_network: '{{ _virtual_network_peering.source.name }}' allow_virtual_network_access: '{{ _virtual_network_peering.allow_virtual_network_access | default(false) }}' allow_forwarded_traffic: '{{ _virtual_network_peering.allow_forwarded_traffic | default(false) }}' remote_virtual_network: resource_group: '{{ _virtual_network_peering.target.resource_group }}' name: '{{ _virtual_network_peering.target.name }}' vars: _virtual_network_peering: allow_virtual_network_access: true allow_forwarded_traffic: true source: name: 'vnet-hub' resource_group: 'rg-francecentral-networking-hub' target: name: 'rg-aks-bootstrap-networking-spoke' resource_group: 'vnet-spoke'
Subnet
Create subnet
-
$resourceGroup = "rg-aks-bootstrap-networking-spoke" $vnetName = "vnet-spoke" $subnetName = "net-cluster-nodes" $subnetAddressprefix = "10.240.0.0/22" az network vnet subnet create ` -g $resourceGroup ` --vnet-name $vnetName ` -n $subnetName ` --address-prefixes $subnetAddressprefix
-
Source : https://docs.ansible.com/ansible/latest/collections/azure/azcollection/azure_rm_subnet_module.html
- name: Create Subnet azure.azcollection.azure_rm_subnet: resource_group: '{{ _virtual_network.resource_group }}' name: '{{ _subnet.name }}' address_prefix: '{{ _subnet.address_prefix }}' virtual_network: '{{ _virtual_network.name }}' state: '{{ _subnet.state | default("present") }}' vars: _virtual_network: resource_group: 'rg-aks-bootstrap-networking-spoke' name: 'vnet-spoke' _subnet: name: 'net-cluster-nodes' address_prefix: '10.240.0.0/22'
List subnet
-
- name: List all subnet in virtual networks azure.azcollection.azure_rm_subnet_info: resource_group: '{{ _virtual_network.resource_group }}' virtual_network_name: '{{ _virtual_network.name }}' vars: _virtual_network: resource_group: 'rg-aks-bootstrap-networking-spoke' name: 'vnet-spoke'
Get subnet info
-
$resourceGroup = "rg-aks-bootstrap-networking-spoke" $vnetName = "vnet-spoke" $subnetName = "net-cluster-nodes" az network vnet subnet show -g $aksresourceGroup --vnet-name $vnetName -n $nodesSubnetName --query "id" -o tsv
-
- name: Get subnet info azure.azcollection.azure_rm_subnet_info: resource_group: '{{ _virtual_network.resource_group }}' virtual_network_name: '{{ _virtual_network.name }}' name: '{{ _subnet_name }}' vars: _virtual_network: resource_group: 'rg-aks-bootstrap-networking-spoke' name: 'vnet-spoke' _subnet_name: 'net-cluster-nodes'
Get available ip
-
$resourceGroup = "rg-aks-bootstrap-networking-spoke" $vnetName = "vnet-spoke" $subnetName = "net-cluster-nodes" az network vnet subnet list-available-ips --resource-group $aksresourceGroup --vnet-name $vnetName -n $nodesSubnetName
-
Get Available IP are not implemented with ansible module
It seems that no ansible module exist to retrieve available IP.