Giter VIP home page Giter VIP logo

ansible-intel-azure-linux-vm's Introduction

Intel Logo

Intel® Optimized Cloud Modules for Ansible

© Copyright 2024, Intel Corporation

Ansible Intel Azure VM - Linux VM

This example creates an Azure Virtual Machine on Intel Icelake CPU on Linux Operating System. The virtual machine is created on an Intel Icelake Standard_D2_v5 by default.

As you configure your application's environment, choose the configurations for your infrastructure that matches your application's requirements. In this example, the virtual machine is using a preconfigured network interface, subnet, and resource group and has an additional option to enable boot diagnostics. The tags Name, Owner and Duration are added to the virtual machine when it is created.

Explained Ansible Azure VM - Linux VM collection

This collection included 2 roles and 3 playbooks.

Role:- Ansible roles are a way to reuse and organize your Ansible code. They are self-contained units that contain all the files and configuration needed to automate a specific task. Roles are defined using a directory structure with specific directories for tasks, variables, files, templates, and other artifacts. This structure makes it easy to find and reuse code, and it also makes it easy to extend behaviour of roles.

To use a role in an Ansible playbook, you simply need to list it in the roles section of the playbook. Ansible will then automatically load the role and execute its tasks.

For this module, There are 2 roles.

  1. azure_rhel_vm_multi_disks - It creates multiple disks on an Azure virtual machine on Intel Icelake CPU on Linux Operating System
  2. azure_rhel_vm_spot_vm creates a Spot Azure Virtual Machine on Intel Icelake CPU on Linux Operating System

** **Playbook:- An Ansible playbook is a YAML file that describes the tasks, are composed of a series of plays, which are groups of tasks that are executed in a specific order. Each play defines a set of tasks that should be executed on a specific group of hosts. Playbooks can also include variables, which can be used to store data that is used by the tasks. This makes it easy to reuse playbooks for different environments and configurations. for this module. For this module, There are 3 playbooks, Where

  1. Playbook intel_azure_linux_vm.yml - Used to creates an Azure Virtual Machine on Intel Icelake CPU on Linux Operating System, it uses Terraform module terraform-intel-azure-linux-vm and being called by Ansible module community.general.terraform
  2. Playbook intel_azure_rhel_vm_multi_disks.yml - It executes role called azure_rhel_vm_multi_disks
  3. Playbook intel_azure_rhel_vm_spot_vm.yml - It executes role called azure_rhel_vm_spot_vm
.
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── galaxy.yml
├── playbooks
│   ├── intel_azure_linux_vm.yml
│   ├── intel_azure_rhel_vm_multi_disks.yml
│   └── intel_azure_rhel_vm_spot_vm.yml
├── README.md
├── requirements.txt
├── requirements.yml
├── roles
│   ├── azure_rhel_vm_multi_disks
│   │   ├── defaults
│   │   │   └── main.yml
│   │   ├── files
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── meta
│   │   │   └── main.yml
│   │   ├── README.md
│   │   ├── tasks
│   │   │   ├── download_tf_module.yml
│   │   │   ├── main.yml
│   │   │   ├── managed_disk.yml
│   │   │   ├── output.yml
│   │   │   ├── read_tfstate.yml
│   │   │   └── vm.yml
│   │   ├── templates
│   │   ├── tests
│   │   │   ├── inventory
│   │   │   └── test.yml
│   │   └── vars
│   │       └── main.yml
│   └── azure_rhel_vm_spot_vm
│       ├── defaults
│       │   └── main.yml
│       ├── files
│       ├── handlers
│       │   └── main.yml
│       ├── meta
│       │   └── main.yml
│       ├── README.md
│       ├── tasks
│       │   ├── download_tf_module.yml
│       │   ├── main.yml
│       │   ├── output.yml
│       │   └── rhel_vm.yml
│       ├── templates
│       ├── tests
│       │   ├── inventory
│       │   └── test.yml
│       └── vars
│           └── main.yml
└── security.md

Authenticate Azure

  1. Download and Install Azure CLI: https://learn.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=dnf
  2. Authenticate Azure CLI: https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest#az-login

Installation of collection

Below are ways to install and use it:

  1. Case 1:- When user's needs can be met with the default configuration, and they want to install a collection from Ansible Galaxy to the default location (as a third-party collection), it is recommended to use the following command:

        ansible-galaxy  collection install <ansible-intel-azure-linux-vm>
    
  2. Case 2:- When user's needs can't be met with the default configuration, wants to extend/modify existing configuration and flow, They can install collection using Ansible Galaxy in user's define location Use below approaches

    1. ansible-galaxy  collection install -p <local path> <ansible-intel-azure-linux-vm>
      

      Note: collection will download collection, you can remove as per need

    2. Download source and Copy role directory to your Ansible boilerplate from GitHub (Used to extended behavior of role)

      git clone https://github.com/OTCShare2/ansible-intel-azure-linux-vm.git
      cd ansible-intel-azure-linux-vm
      cp -r role/azure_rhel_vm_multi_disks /<your project path>/
      

Requirements

Name Version
Terraform =1.5.7
Azure CLI ~> 2.54.0
Ansible Core ~>2.14.2
Ansible ~>7.2.0-1

Note:

  1. Install requirements using requirements.txt and requirements.yml, Use below command:
    pip3 install -r requirements.txt
    ansible-galaxy install -r requirements.yml
  2. Above role requires Terraform as we are executing terraform module terraform-intel-azure-linux-vm using Ansible module called community.general.terraform

Usage

Use playbook to execute Terraform module terraform-intel-azure-linux-vm using Ansible module community.general.terraform as below

- hosts: localhost
  vars:
    terraform_source: https://github.com/intel/terraform-intel-azure-linux-vm.git
  tasks:
    - set_fact:
        terraform_module_download_path: '/home/{{ansible_env.USER}}/terraform/main/intel_azure_linux_vm/'

    - name: Clone a github repository
      git:
        repo: '{{ terraform_source }}'
        dest: '{{ terraform_module_download_path }}'
        clone: yes
        update: yes
        version: main

    - name: Azure linux vm
      community.general.terraform:
        project_path: '{{ terraform_module_download_path }}'
        state: present
        force_init: true
        complex_vars: true
        # for additional variables
        # https://github.com/intel/terraform-intel-azure-linux-vm/blob/main/variables.tf
        variables:
          azurerm_resource_group_name: "rg-intel-29112023"
          azurerm_virtual_network_name: "vnet1"
          virtual_network_resource_group_name: "rg-intel-29112023"
          virtual_machine_size: "Standard_D2s_v3"
          azurerm_subnet_name: "default"
          admin_password: "Password@123"
          tags:
            owner: [email protected]
            duration: 1
      register: vm_output

    - debug:
        var: vm_output

Use below Command:

ansible-playbook intel_azure_linux_vm.yml

Run Ansible with Different State

State - planned (terraform plan)

- name: Azure linux vm
  community.general.terraform:
    project_path: '{{ terraform_module_download_path }}'
    state: planned
    force_init: true
    complex_vars: true
    # for additional variables
    # https://github.com/intel/terraform-intel-azure-linux-vm/blob/main/variables.tf
    variables:
      azurerm_resource_group_name: "rg-intel-29112023"
      admin_password: "Password@123"
  register: vm_output

State - present (terraform apply)

- name: Azure linux vm
  community.general.terraform:
    project_path: '{{ terraform_module_download_path }}'
    state: present
    force_init: true
    complex_vars: true
    # for additional variables
    # https://github.com/intel/terraform-intel-azure-linux-vm/blob/main/variables.tf
    variables:
      azurerm_resource_group_name: "rg-intel-29112023"
      admin_password: "Password@123"
  register: vm_output

State - absent (terraform destroy)

- name: Azure linux vm
  community.general.terraform:
    project_path: '{{ terraform_module_download_path }}'
    state: absent
    force_init: true
    complex_vars: true
    # for additional variables
    # https://github.com/intel/terraform-intel-azure-linux-vm/blob/main/variables.tf
    variables:
      azurerm_resource_group_name: "rg-intel-29112023"
      admin_password: "Password@123"
  register: vm_output

See roles folder for complete examples

Role Name
azure_rhel_vm_multi_disks
azure_rhel_vm_spot_vm

Inputs

Name Description Type Default Required
admin_password The Password which should be used for the local-administrator on this virtual machine string n/a yes
admin_ssh_key n/a list(any) [] no
admin_username The username of the local administrator used for the virtual machine string "adminuser" no
azurerm_network_interface_name The name of the network interface. Changing this forces a new resource to be created string "nic1" no
azurerm_resource_group_name Name of the resource group to be imported string n/a yes
azurerm_storage_account_name The name of the storage account to be used for the boot_diagnostic string null no
azurerm_subnet_name The name of the preconfigured subnet string n/a yes
azurerm_virtual_network_name Name of the preconfigured virtual network string n/a yes
disable_password_authentication Boolean that determines if password authentication will be disabled on this virtual machine bool false no
disk_size_gb The size of the internal OS disk in GB, if you wish to vary from the size used in the image this virtual machine is sourced from string null no
enable_boot_diagnostics Boolean that determines if the boot diagnostics will be enabled on this virtual machine bool true no
eviction_policy Specifies what should happen when the Virtual Machine is evicted for price reasons when using a Spot instance. Possible values are Deallocate and Delete string "Deallocate" no
identity n/a
object({
identity_ids = optional(list(string))
principal_id = optional(string)
tentant_id = optional(string)
type = optional(string, "SystemAssigned")
})
{} no
ip_configuration_name A name for the IP with the network interface configuration string "internal" no
ip_configuration_private_ip_address_allocation The allocation method used for the private IP address. Possible values are Dynamic and Static string "Dynamic" no
ip_configuration_public_ip_address_id Reference to a public IP address for the NIC string null no
max_bid_price The maximum price you're willing to pay for this virtual machine, in US Dollars; which must be greater than the current spot price. If this bid price falls below the current spot price the virtual machine will be evicted using the eviction_policy string "-1" no
os_disk_caching The type of caching which should be used for the internal OS disk. Possible values are 'None', 'ReadOnly' and 'ReadWrite' string "ReadWrite" no
os_disk_name The name which should be used for the internal OS disk string "disk1" no
os_disk_storage_account_type The type of storage account which should back this the internal OS disk. Possible values include Standard_LRS, StandardSSD_LRS and Premium_LRS string "Premium_LRS" no
priority Specifies the priority of this virtual machine. Possible values are Regular and Spot. Defaults to Regular string "Regular" no
route_tables_ids A map of subnet name for the route table ids map(string) {} no
source_image_reference_offer Specifies the offer of the image used to create the virtual machine string "0001-com-ubuntu-server-jammy" no
source_image_reference_publisher Specifies the publisher of the image used to create the virtual machine string "Canonical" no
source_image_reference_sku Specifies the SKU of the image used to create the virtual machine string "22_04-lts-gen2" no
source_image_reference_version Specifies the version of the image used to create the virtual machine string "latest" no
tags A mapping of tags to assign to the resource map(any) {} no
virtual_machine_size The SKU that will be configured for the provisioned virtual machine string "Standard_D2s_v5" no
virtual_network_resource_group_name Name of the resource group of the virtual network string n/a yes
vm_name The unique name of the Linux virtual machine string "vm1" no
write_accelerator_enabled Should write accelerator be enabled for this OS disk? Defaults to false bool false no

Outputs

Name Description
admin_username Virtual machine admin username
identity Identity configuration associated with the virtual machine
location Location where the virtual machine will be created
name Virtual machine name
network_interface_ids List of network interface IDs that are attached to the virtual machine
os_disk Disk properties that are attached to the virtual machine
resource_group_name Name of the resource group
size The SKU for the virtual machine
storage_account_tier Tier to identify the storage account associated with the virtual machine
tags Tags that are assigned to the virtual machine
virtual_machine_id ID assigned to the virtual machine after it has been created

ansible-intel-azure-linux-vm's People

Contributors

ajaycloudops09 avatar akhilcalsoft23 avatar kevinbleckmann avatar lucasmelogithub avatar rdower avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.