Simplifying Installing Software on Azure Virtual Machine - Cloud Init | Scribe

    Simplifying Installing Software on Azure Virtual Machine - Cloud Init

    • Hafeez Baig |
    • 11 steps |
    • 2 minutes
    1
    Sign in into the **Microsoft Azure Portal**
    information ordinal icon
    Refer to this guide to create an azure virtual machine - give the name as "**my-second-vm**"<https://scribehow.com/shared/Creating_your_first_Virtual_Machine_in_Azure__m7sJfxD7SKOuonRH8SNW2A>
    2
    While creating the **Virtual Machine**, click on the **Advanced** tab
    3
    Scroll to the **Custom data and cloud init** section, type the bash script in the text input field\ \ [[#!/bin/sh]]\ [[sudo su ]]\ [[apt-get -y update]]\ [[apt-get -y install nginx ]]\ [[echo "Hello World" &gt;/var/www/html/index.html]]
    information ordinal icon
    **What will this bash script do?** This bash script automates tasks sequentially as the Azure VM initializes. It updates packages, installs Nginx, and adds a file via the echo command to display "**Hello World**" on the webpage.
    information ordinal icon
    **What is cloud-init in Azure VM?** In Azure VMs, cloud-init is a widely used tool for initializing cloud instances during the deployment process. It allows you to automate tasks such as setting up user accounts, configuring networking, installing packages, and running scripts on VM startup.
    4
    Scroll the page and click on the **Review + create** button
    5
    Wait for the Validation to get passed
    alert ordinal icon
    If your validation is displaying errors and hasn't passed, try troubleshooting by repeating previous steps and checking the validation again.
    6
    After the Validation is successfully passed, scroll the page and click on the **Create** button
    7
    **Your deployment is complete** wizard will open, Azure Virtual Machine has been successfully created
    8
    Click on the **Go to resource** button
    9
    **my-second-vm** wizard will open, locate the **Public IP address** and click on the copy widget
    10
    Open a new tab in the browser and paste the **Public IP address**
    11
    **Hellow World** is displayed on the web page
    information ordinal icon
    To print the hostname with the text "Welcome to in28minutes", then type the command [[echo "Welcome to in28minutes $(hostname)" &gt; /var/www/html/index.html]]
    information ordinal icon
    **What does the command** `echo "Welcome to in28minutes $(hostname)" > /var/www/html/index.html` **do?** The command writes a message to the file `/var/www/html/index.html`. It includes the text `"Welcome to in28minutes"` followed by the machine's hostname. The `$(hostname)` part dynamically inserts the current hostname of the machine. Any existing content in the file will be replaced with this new message.
    information ordinal icon
    Congratulations on completing this lab, Simplifying Installing Software on Azure Virtual Machine - Cloud init! Good Job!