How it works...

In step 1, we created a virtual network with the name vnet01 within the same resource group we used in the first recipe, Creating an Azure virtual machine. Since we are using a resource group, the resources can pick the default location of the resource group. We have defined the CIDR network addresses as 10.2.0.0/24 and 172.1.0.0/16. We can also define multiple network addresses using YAML syntax.

We should note here that if we want to delete an existing virtual network, we can set the state to absent. By default, most of the Ansible modules have their state set to present.

In step 2, we created a subnet using the azure_rm_subnet module inside the virtual network vnet01.

In step 3, we created a network interface card using azure_rm_networkinterface and named it nic01. We specified the public_ip as no, which will ensure that Azure will not allocate any public IP address to the NIC, but also that NIC will be associated with a private IP from the subnet address space.

After creating the NIC, we register the output of this module in the network_interface variable to display its properties in step 4.

In step 4, we use the debug module to print the private IP address allocated to the network interface using the variable registered in step 3.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset