Problem statement
Create a Virtual Machine with the following configurations by using Ansible Script.
Region: (US) East US
Availability options: No infrastructure redundancy required
Security type: Standard
Image: Ubuntu Server 20.04 LTS - Gen2
Size: Standard_B2ms
Authentication type: SSH public key
SSH public key source: Generate new key pair
OS disk type: Standard HDD
Security Group:
- Inbound rule: Allow SSH, HTTP, and HTTPS
- Outbound rule: Allow All
Notes
Launch Both Azure Basics Lab and Ubuntu Challenge Lab in new tabs.
You must click on the Credentials button on the top right corner of Ubuntu Challenge Lab to allow typing within the environment.
Utilize Ubuntu Challenge Lab to perform an Ansible Script.
Ansible and Python3 are already Installed in the Playground. Install rest of the required dependencies for ansible.
Use the credentials given in the Azure Basics Lab to log in to the Azure Portal.
After completing the hands-on, delete all the resources created.
Once you complete the challenge click on the Power button on the top right corner to terminate the playground.
Ansible playbook that creates a Virtual Machine in Azure with the given configurations:
create 'create_vm.yml' and write the below code
--- - name: Create Azure Virtual Machine hosts: localhost gather_facts: no tasks: - name: Create Resource Group azure_rm_resourcegroup: name: myResourceGroup location: eastus state: present - name: Create Virtual Network azure_rm_virtualnetwork: name: myVNet resource_group: myResourceGroup location: eastus address_prefixes: "10.0.0.0/16" state: present - name: Create Subnet azure_rm_subnet: name: mySubnet resource_group: myResourceGroup virtual_network_name: myVNet address_prefix: "10.0.0.0/24" state: present - name: Create Public IP azure_rm_publicipaddress: name: myPublicIP resource_group: myResourceGroup location: eastus allocation_method: Static state: present - name: Create Network Security Group azure_rm_securitygroup: name: myNSG resource_group: myResourceGroup location: eastus security_rules: - name: AllowSSH protocol: Tcp destination_port_range: "22" access: Allow direction: Inbound - name: AllowHTTP protocol: Tcp destination_port_range: "80" access: Allow direction: Inbound - name: AllowHTTPS protocol: Tcp destination_port_range: "443" access: Allow direction: Inbound state: present - name: Create Virtual Network Interface azure_rm_networkinterface: name: myNIC resource_group: myResourceGroup location: eastus subnet_name: mySubnet public_ip_name: myPublicIP security_group_name: myNSG state: present - name: Generate SSH Key ansible.builtin.ssh_keypair: path: "{{ playbook_dir }}/id_rsa" size: 2048 - name: Create Virtual Machine azure_rm_virtualmachine: name: myVM resource_group: myResourceGroup location: eastus vm_size: Standard_B2ms admin_username: myAdmin ssh_password_enabled: no ssh_public_keys: - path: /home/myAdmin/.ssh/authorized_keys key_data: "{{ lookup('file', playbook_dir + '/id_rsa.pub') }}" os_type: Linux image: offer: UbuntuServer publisher: Canonical sku: 20.04-LTS version: latest os_disk_caching: ReadOnly data_disks: [] network_interfaces: [myNIC] state: present
Comments
Post a Comment