Install Elasticsearch VM Azure Dengan Ansible/Ansible AWX | Scripts

Ayies kali ini mau share buat VM Elastic Search di Azure dengan menggunakan Ansible/Ansible AWX/Ansible Tower.

Pastikan kamu telah install Elastic Search roles di Ansible Galaxy. https://galaxy.ansible.com/elastic/elasticsearch

Atau kalau mau manual download file zipnya dan satukan dengan file yml yang akan ayies share.Berikut script yml-nya, buat dan simpan sebagai contoh: elasticsearch.yml

- hosts: localhost
  connection: local

# var: <--variable untuk konfigurasi uncomment semua&sesuaikan yang kamu mau (hilangkan #)
  #vm_offer: "UbuntuServer"
  #vm_pub: "Canonical"
  #vm_sku: "18.04-LTS"
  #vm_size: "Standard_D2s_v3"
  #az: "southeastasia"
  #vm_Name: "elastic-search-vm"
  #resource_group: "resource-group-ibrahim"
  #os_user: "ibrahim"
  #ssh_key: "ssh-rsa AAAAxxxxxxxxxxxxxxxxxxxx"
  #admin_password: "xxxxxxxxx"


  tasks:

  - name: Create a resource group
    azure_rm_resourcegroup:
      name: "{{ resource_group }}"
      location: "{{ az }}"
      tags:
        testing: testing
        delete: never

  - name: Create virtual network
    azure_rm_virtualnetwork:
      resource_group: "{{ resource_group }}"
      name: "{{ vm_Name }}"
      address_prefixes: "10.0.0.0/16"

  - name: Add subnet
    azure_rm_subnet:
      resource_group: "{{ resource_group }}"
      name: "{{ vm_Name }}"
      address_prefix: "10.0.1.0/24"
      virtual_network: "{{ vm_Name }}"

  - name: Create public IP address
    azure_rm_publicipaddress:
      resource_group: "{{ resource_group }}"
      allocation_method: Static
      name: "{{ vm_Name }}"
    register:  output

  - debug: var=output

  - name: Create Network Security Group that allows SSH
    azure_rm_securitygroup:
      resource_group: "{{ resource_group }}"
      name: "{{ vm_Name }}"
      rules:
        - name: SSH
          protocol: Tcp
          destination_port_range: 22
          access: Allow
          priority: 1001
          direction: Inbound

  - name: Create virtual network interface card
    azure_rm_networkinterface:
      resource_group: "{{ resource_group }}"
      name: "{{ vm_Name }}"
      virtual_network: "{{ vm_Name }}"
      subnet: "{{ vm_Name }}"
      public_ip_name: "{{ vm_Name }}"
      security_group: "{{ vm_Name }}"

  - name: Create VM
    azure_rm_virtualmachine:
      resource_group: "{{ resource_group }}"
      name: "{{ vm_Name }}"
      vm_size: "{{ vm_size }}"
      admin_username: "{{ os_user }}"
      ssh_password_enabled: true
      admin_password: "{{ admin_password }}"
      ssh_public_keys: 
        - path: "/home/{{ os_user }}/.ssh/authorized_keys"
          key_data: "{{ ssh_key }}"
      network_interfaces: "{{ vm_Name }}"
      image:
        offer: "{{ vm_offer }}"
        publisher: "{{ vm_pub }}"
        sku: "{{ vm_sku }}"
        version: latest


### Ambil IP Public dari hasil create
  - name     : Masukan IP public berikut ke group
    add_host :
      groups: elasticsearch
      hostname: "{{ vm_Name }}"
      ansible_host: "{{ azure_vm.properties.networkProfile.networkInterfaces[0].properties.ipConfigurations[0].properties.publicIPAddress.properties.ipAddress }}"
      ansible_user: "{{ os_user }}"
      ansible_ssh_pass: "{{ admin_password }}"


- name: Install Elasticsearch
  hosts: "{{ vm_Name }}"
  tasks:
  roles:
    - role: elastic.elasticsearch
  vars:
    es_start_service: true

Install Elasticsearch VM Azure 

 

Lalu eksekusi melalui dashboard Ansible Tower/Ansible AWX kamu. Atau untuk manual jalankan perintah berikut: ansible-playbook elasticsearch.yml

 


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *