Build React Native App (4) - Redux, Jest, and NativeBase

Image
From this blog, typescript feature will be added. There are couple of ways to implement static type checking like; flow from facebook, PropTypes and Typescript. Typescript is well integrated with Visual Studio Code and supports better linter, error messages, and intellisense. Reference site Github Sample Ex4 Currnet version D:\GitRepo\reactnative>npm --version 6.3.0 D:\GitRepo\reactnative>react-native --version react-native-cli: 2.0.1 react-native: n/a - not inside a React Native project directory D:\GitRepo\reactnative>yarn --version 1.9.4 Creating React Native App $ react-native init ex4 If you want to specify the version, add "--version 0.57.3" at the end. Add NativeBase to React Native $ npm install native-base --save ... + native-base@2.8.1 added 71 packages from 42 contributors, removed 50 packages, updated 829 packages and audited 34989 packages in 138.542s found 0 vulnerabilities $ $ yarn yarn install v1.9.4 warning package-lock.json found. You...

Automation with Ansible (10) - Create VMs from VCenter with Multi Environment Architecture

Introduction

From this series, all folder structure will be followed from the previous Multi environment stucture.

The steps to create VMs are;

  1. Create Inventory file
  2. Create Variables
    • Shared variables
    • Group variables
  3. Create Ansible Playbook
    • Creating VMs from CentOS Template
    • Set Network interface
    • Add MAC Address to dhcpd.conf
    • Reboot

Reference

Folders/Files list

\---ansible
    |   CreateVMs.yaml
    |   
    +---inventory
    |   +---shared_vars
    |   |       shared-secrets.yml (empty)
    |   |       shared-vars.yml (empty)
    |   |       
    |   \---test
    |       +---dmz
    |       |   |   vm_hosts
    |       |   |   
    |       |   \---group_vars
    |       |           vcenter.yml 
    |       |           
    |       \---internal
    |           |   vm_hosts
    |           |   
    |           \---group_vars
    |                   secrets.yml (empty)
    |                   vcenter.yml
    |                   
    \---tasks
            load-vars.yml            

Create Inventory file

filename: vm_hosts

[docker-vms]
docker01 ipaddr="10.200.0.150"
docker02 ipaddr="10.200.0.151"
docker03 ipaddr="10.200.0.152"
docker04 ipaddr="10.200.0.153"
docker05 ipaddr="10.200.0.154"

Add all computers as many as you want to have

Create Variables

Loading Shared and Group Variables

Loading variables from Shared and Group. "{{ inventory_dir }}" is the directory specified from ansible-playbook command line.

---
- include_vars: "inventory/shared_vars/shared-secrets.yml"
- include_vars: "inventory/shared_vars/shared-vars.yml"
- include_vars: "{{ inventory_dir }}/group_vars/secrets.yml"
- include_vars: "{{ inventory_dir }}/group_vars/vcenter.yml"
- include_vars: "{{ inventory_dir }}/group_vars/docker.yml"

Shared Variables

There are no common data for this task

filename: inventory/shared_vars/shared-vars.yaml


Individual Variables

filename: inventory/{Environment}/{Internal or DMZ}/group_vars/vcenter.yaml

---
vcenter_hostname: 10.200.0.11
vcenter_validate_certs: no
vcenter_username: administrator@vsphere.local
vcenter_password: vcenter_password
vcenter_template: CentOS_Template
vcenter_cluster: VSphere_Cluster_Name
vcenter_resource: /Resources
vcenter_vm_folder: Docker
vcenter_vm_network: "Test-LAN"

Please check the Series 2 for the detail information.

Create Ansible Playbook

The connection will be local from ns01 node which provides following services

  • DNS and DHCP
  • Ansible playbook
  • Docker Image build
  • Maven and Java compile
---
- hosts: all
  pre_tasks:
    - include_tasks: tasks/load-vars.yml
  connection: local
  become: yes
  tasks:
  - name: createVM from Template
    vsphere_guest:
      vcenter_hostname: "{{ vcenter_hostname }}"
      validate_certs: "{{ vcenter_validate_certs }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      guest: "{{ inventory_hostname }}"
      from_template: yes
      template_src: "{{ vcenter_template }}"
      cluster: "{{ vcenter_cluster }}"
      resource_pool: "{{ vcenter_resource }}"
      vm_extra_config:
        folder: "{{ vcenter_vm_folder }}"
  - name: Reconfigre network card
    vsphere_guest:
      vcenter_hostname: "{{ vcenter_hostname }}"
      validate_certs: "{{ vcenter_validate_certs }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      guest: "{{ inventory_hostname }}"
      state: reconfigured
      vm_nic:
        nic1:
          type: vmxnet3
          network: "{{ vcenter_vm_network }}"
          network_type: standard  
      esxi:
        datacenter: FlairTest
  - name: Retrieve Cloned VM
    vsphere_guest:
      vcenter_hostname: "{{ vcenter_hostname }}"
      validate_certs: "{{ vcenter_validate_certs }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      guest: "{{ inventory_hostname }}"
      vmware_guest_facts: yes
    register: clonedvm
  - name: Update DHCPD Entry
    blockinfile:   
      path: /etc/dhcp/dhcpd.conf
      marker: ""
      state: present
      insertafter: EOF
      block: |
        host {{ inventory_hostname }} {
            option host-name "{{ inventory_hostname }}";
            ddns-hostname "{{ inventory_hostname }}";
            hardware ethernet {{ clonedvm.ansible_facts.hw_eth0.macaddress }};
            fixed-address {{ hostvars[inventory_hostname]['ipaddr'] }};
        }
  - name: Restart DHCPD from ansible host
    become: yes
    shell: 'systemctl restart dhcpd'
    async: 30
    poll: 0
    ignore_errors: true

  - name: Boot Cloned VM
    vsphere_guest:
      vcenter_hostname: "{{ vcenter_hostname }}"
      validate_certs: "{{ vcenter_validate_certs }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      guest: "{{ inventory_hostname }}"
      state: powered_on
  - debug:
      var: clonedvm 

Running command

For Internal Docker VMs

[ansible@ns01 ansible]$ ansible-playbook -i inventory/test/internal/vm_hosts Vsphere-CreateVM.yaml --extra-vars "ansible_sudo_pass=root_password" --ask-pass

For DMZ Docker VMs

[ansible@ns01 ansible]$ ansible-playbook -i inventory/test/dmz/vm_hosts Vsphere-CreateVM.yaml --extra-vars "ansible_sudo_pass=root" --ask-pass

"-i" is the option for the inventory. "{{ inventory_dir}}" will be the folder from this option. In this case, "{{ inventory_dir }}" will return "inventory/test/dmz".

"--ask-pass" is not necessary. This is to run command from remote connection with root permmission. However, for the consistency for the rest command, just used from the command

Result

Create VMs Result

Summary

Next tutorial will show you how to build docker cluster which created from this tutorial

Comments

Popular posts from this blog

Build React Native App (4) - Redux, Jest, and NativeBase

Replacing text in PDF file using iTextSharp

Using GIT(Bitbucket), Visual Studio Code