Wednesday, May 19, 2021

Find files and directories with UID,GID,Sticky bit set

 Find files and directories with UID,GID,Sticky bit set


# find ./ -type -d -perm 1000 -exec ls -ld {} \;

# find ./ -type f  \( -perm -2000 -o -perm -4000 \) -exec ls -ld {} \;

 

$ ansible -i hostlist all -o -a "ls -l /etc/resolv.conf" | sort | grep -v "Mar 20 10"

 

Day7 - Terraform variable multi instances deployment

Day 7


$ cat providers.tf





$ cat variables.tf

variable 'x' {
   default = "t2.micro"
     type = string
}

output "01" {
  value = var.x
}



> tf apply -var-'x-t2.medium"


$ cat aws-main.tf
resource "aws_instance" "web" {
  ami    = "ami-012...."
  instance_type    = var.x

}



$ cat variables.tf

# variable 'x' {
#    default = "t2.micro"
#     type = string
# }

variable 'x' {}

output "01" {
  value = var.x
}

> tf apply -var="x=t2.medium"

in this case, either you pass the value or it will prompt

don't change the code, pass the variable.

or you can create a config with key/value pair.

name must the same, fix file.
> notepad terraform.tfvars
#x="value"
x="t2.micro"

here, you can come and change
we change the value of x.

> tf apply

if you don't define, it will prompt but we defined, it will not prompt but will grab from config file.



> notepad terraform.tfvars
#x="value"
x="t2.large"

> tf apply -var="x=t2.micro"


Lets go to variable file


$ cat variables.tf

# variable 'x' {
#    default = "t2.micro"
#     type = string
# }

variable 'x' {}

variable "y" {
  type=boot

}


output "01" {
  value = var.y
}

commentout the content on aws_main.tf file.

> tf apply
ask you for true or false


boolean is good if you create condition
if you want to do something check the condition, if condition is true, do this if not do the else part.

turnety operator way ,,

condition - question mark? - value1: value2

if condition comes true, display value1 else display value2


Note: true and false should be on lower case

output "01" {
  value = var.y ? "Sam" : "Ram"
}

if true it will return Sam else Ram.



> cd google

provider "aws" {
 region    = "ap-south-1"
  profile    = "default"

}

provider "google" {
   project    = "myproj"
   region    = "asia-south1"
}


$ modify variable file

> tc apply

> tf plan

webapp    -> Testing (QA Team) -> Prod


$ cat aws_main.tf
resource "aws_instance" "web" {
 ami    = "ami-01..."
 instance_type = var.x
 count = 5

}


cat variables.tf
append
variable "lstest" {
type = bool

}

change the value of 5

$ cat aws_main.tf
resource "aws_instance" "web" {
 ami    = "ami-01..."
 instance_type = var.x
# count = 5
 count = var.lstest ? 0    : 1    # if this is true, 0 , count 0 , this instance will not run

}


gcp_main.tf
resource "google_compute_instance" os1" {
  name    = "os1"
  machine_type = var.mtype
  zone    = "asia-south-c"
  count = var.istest ? 1 : 0

boot_disk {
  initialize_params {
    image = "debian-cloud/debian-g"
  }
}

> tf apply -var="lstest=true"


ca variables.tf
append


variable "lstest" {
type = bool

}

variable "azaws" {
default = [ "ap-south-1a", "ap-south-1b", "ap-south-1c" ]
type = list
}

#output "0s2" {
#  value = var.azaws


$ cat aws_main.tf
resource "aws_instance" "web" {
 ami    = "ami-01..."
 instance_type = var.x
 availability_zone = var.azaws[1]
 count = 1

}


> tf apply




map data type

[ 'a', 'b', 'c' ]

system gives the index

you may want to do your own value
say a is id




variable "azaws" {
default = [ "ap-south-1a", "ap-south-1b", "ap-south-1c" ]
type = list
}

variable "types" {
  type = map
  default = {        # maps in curly braces
    us-est-1 = "t2.nano",
        ap-south-1 = "t2.micro",
        us-west-1 = "t2.medium"
  }
}


# output "os3" {
#   value = var.types
#   value = var.types["ap-south-1"]
# }


> tf apply



Tuesday, May 18, 2021

आफ्नै धर्तीलाई सम्झंदा !!!

आफ्नै धर्तीलाई सम्झंदा !!!

नयाँ भाग्य कोर्न  
नयाँ मुलुकको लागी
जब घर देश बाट हिंड्छ
परिवारको भविष्यलाई
राम्रोसँग स्रिङ्गारेर
खुशि,र दुखको दोसाँझमा
अल्मलिंदै, रुमलिंदै
आफ्नो प्यारो गाउँ बेशि
पाईला पाईलाले पछि पार्दै
नयाँ  सपना सम्झंदै
एउटा उदेष्यमा  लम्किन्छ - परदेशी

परिवारमा बात कम
खबर कम भो परदेश बाट
न गफ छ, न भेट छ
सुन्य सुन्य छ
एकान्त छ,
उता,
आमा पिंढिमा  बसेर
सोध्छिन रे !
छोरा कहिले आउँछ ?
छोरा दिन गन्दै,
महिना अनि बर्ष गन्दै
समयको वहावमा
यसरि चल्दै छ,
थाहा छैन जीवन
कहाँ पुग्दै छ,
शरीरको रुपरेखा बदलिंदै छ
कपाल फुलेर
कनिका छरे जस्तै भो
खै के को खोजीमा
केहि पाए जस्तो
केहि नपाए जस्तो
दोधारको जिन्दगी
सबै मिलेर नि
कतै केहि नमिले जस्तो
केहि छुटे जस्तो
सन्तोषको सास
फेर्न नसके जस्तो
न देश अट्यो न परिवार
यो मनमा सांच्न लाई
नयाँ मुलुक, नयाँ संसार,
नयाँ  परिवार
अनि नयाँ परिवेश भो विदेश !!!

न देश भो
न भो परिवार यो मनमा साँच्न लाई

न त् देश न त् परिवार

सिक्का हावामा पल्टाएर
भाग्य बदल्न सकिने रहेनछ
बर्मा गए कर्म संगै
त्यसै भएको रहेनछ
सबैको भाग्य एउटै
हुँदो रहेनछ !!!
sikkaa paltaaer sahi halat chuttaaun sakinna



५/१८/२०२१
Vienna, VA

Day6-terraform on google - GCE

 day6-terraform on google - GCE

> gcloud init

create account on gcloud

Instance/VM

compute service - EC2


In your account first
1. create a project.
- create service
- create database service
- deploy webus/cli/api


based on the project, blling and everything

1. click on your account and
create new project (through web or GUI or CLI) to create a new project

Name: myterraform

remember to note the ID, which is also the project IP. Give name wisely. its very imporant

now, you will be on project.

click o your account and you will see what project you are in.

on the left side, you will see different menus services and you can directly launch fromt here.

click on compute Engine -> VM instances

-> compute Engine API

click on enable to activate it..



google: gcp region list
global locations


COde:

Goal: Step by step
-------------------


step1

Login: auth: user/pass
code: Key
Project ID: myterraform
region: asia_south1



=========================

go to terraform : searh provider: google
- google provider
- authentication

look for credential


> mkdir day5; cd day5
> notepad main.tf


provider "gogole" {
  project    = "myterraform"
  region    = "asia-south1"

}

look for authentication part

- we use access key to login and store in a file.
  - create service account
  - create key and store in a file

IAM and Admin
-> service account -> You will see your existing account.
-> this account is associated some policy or role
-> click on it and click on Keys
-> click on add key - create new key
-> select JSON (by default)
-> Click on Create and will be downloaded on your local PC.
Note: Keey it secret

go to documents/terraform-training/google/gce-key.json



> notepad main.tf

provider "gogole" {
  project    = "myterraform"
  region    = "asia-south1"
  credentials     = "gce-key.json"
}


> terraform init

downloads the plugins for provider


go back to compute service, and write how to launch manually
- computer Engine -> VM instance -> Create a new instance


give os name: os2
vm: os2
region: select mumbai
instance type - machine family -> by default E2-medium
machineType: ec-medium
boot disk (AMI) - click on change and select the os you want.
specify boot-disk image name: debian
boot disk type and size: 10G

go to network settting
click on management / networking
VPC/Network: default (Network Interface)



give os

name: os2
vm: os2
region: select mumbai
instance type - machine family -> by default E2-medium
machineType: ec-medium
boot disk (AMI) - click on change and select the os you want.
specify boot-disk image name: debian
boot disk type and size: 10G

go to network settting
click on management / networking
VPC/Network: default (Network Interface)

convert it into terrafrom code.


google for google service acount and look for example.



> notepad main.tf

provider "gogole" {
  project    = "myterraform"
  region    = "asia-south1"
  credentials     = "gce-key.json"
}

resource "google_compute_instance" "os1"
  name        = "os1"
  machine_type    = "e2-medium"
  zone:     = "asia_south1"
}
 

tags =

look for document what keyworks are optional and mandetory

> terraform plan

errors: account_id is require


google for: gcloud cli command
go to cloud sdk and click on install SDK and click on cloud DSK installer

after you install, one cmd is avialable..
> gcloud init
helps you to login

select 2
enter project name:
it will configure on  your local system.

now, try again
> terrafro plan




> notepad main.tf

provider "gogole" {
  project    = "myterraform"
  region    = "asia-south1"
  credentials     = "gce-key.json"
}

resource "google_compute_instance" "os1"
  name        = "os1"
  machine_type    = "e2-medium"
  zone:     = "asia_south1"
}
 

> tf plan

need to specify network interface, book disk required

copy the example code

> notepad main.tf

provider "gogole" {
  project    = "myterraform"
  region    = "asia-south1"
  credentials     = "gce-key.json"
}

resource "google_compute_instance" "os1" {
  name        = "os1"
  machine_type    = "e2-medium"
  zone:     = "asia_south1-c"
}

boot_disk {
  initialize_params {
    image = "debian-cloud/debian-9"

network_interface {
  network = "default"
}

>tf plan
> tf apply

error: if any, review

otherwise, instance should be created.


go to the console and see if you ca see other insances.



> tf destroy --help

destroy specific resource
> tf destroy -target=resource


>

>

Thursday, May 13, 2021

mAya jaal

 
हिमचुलीमा हिउँ कति पर्यो पर्यो
कति पर्यो भन्न म सक्दिन
तिम्लाई माया कति छ कति
मुटु चिरी देखाउन सक्दिन

when logic ends, magic begins ..


सालको पातको टपरी हुनी

 
सालको पातको टपरी हुनी

केटा: भाको एउटा जाले रुमाल फूल भरेको छैन,
आ… होएऽऽऽ भाको एउटा जाले रुमाल फूल भरेको छैन,
के लैजान्छौ सानू तिम्ले पिरतीमा बैना, पिरतीमा बैना…
एऽऽऽ हे बरै…
सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति, हे बरै नलाउ पछि हल्लैको; - 2

केटी: मुटु कहाँ बैना मार्यो मै सोझीलाई जलाई,
आ… होएऽऽऽ मुटु कहाँ बैना मार्यो मै सोझीलाई जलाई,
कलेजीमा झुपडी देउ रुमाल नदेउ मलाई, रुमाल नदेउ मलाई…

केटी: पानीको रिस उर्ने माछी काँ'होला र सानू,
आ… होएऽऽऽ पानीको रिस उर्ने माछी काँ'होला र सानू,
डालीको रिस ठू्ल्ने गरे मैले त के जानूँ, मैले त के जानूँ…

केटी: छेउमै छ नि लालि फूल प्याउली किन हेर्छौ,
आ… होएऽऽऽ छेउमै छ नि लालि फूल प्याउली किन हेर्छौ,
जुगै काट्ने मन छ मलाई मन किन फेर्छौ, मन किन फेर्छौ…

केटा: आउँदा जाँदा देउरालीमा फूल चराउँछु मैले,
आ… होएऽऽऽ आउँदा जाँदा देउरालीमा फूल चराउँछु मैले,
तिम्लाई सम्झी चढाको फूल ओइलिँदैन कहिल्यै, ओइलिँदैन कहिल्यै…

केटी: जोडी पंक्षी देखेपनी घर मुनिको बोटमा,
आ… होएऽऽऽ जोडी पंक्षी देखेपनी घर मुनिको बोटमा,
तारा खस्दा तिम्रै नाम आउँछ मेरो ओंठमा, आउँछ मेरो ओंठमा…
एऽऽऽ हे बरै…


=======================================

केटा: भाको एउटा जाले रुमाल फूल भरेको छैन,
आ… होएऽऽऽ भाको एउटा जाले रुमाल फूल भरेको छैन,
के लैजान्छौ सानू तिम्ले पिरतीमा बैना, पिरतीमा बैना…
एऽऽऽ हे बरै… सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति, हे बरै नलाउ पछि हल्लैको;
हा… हैऽऽऽ सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।

केटी: मुटु कहाँ बैना मार्यो मै सोझीलाई जलाई,
आ… होएऽऽऽ मुटु कहाँ बैना मार्यो मै सोझीलाई जलाई,
कलेजीमा झुपडी देउ रुमाल नदेउ मलाई, रुमाल नदेउ मलाई…
एऽऽऽ हे बरै… सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति, हे बरै नलाउ पछि हल्लैको;
हा… हैऽऽऽ सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।

-------------------------

केटी: पानीको रिस उर्ने माछी काँ'होला र सानू,
आ… होएऽऽऽ पानीको रिस उर्ने माछी काँ'होला र सानू,
डालीको रिस ठू्ल्ने गरे मैले त के जानूँ, मैले त के जानूँ…
एऽऽऽ हे बरै… सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति, हे बरै नलाउ पछि हल्लैको;
हा… हैऽऽऽ सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।

केटी: छेउमै छ नि लालि फूल प्याउली किन हेर्छौ,
आ… होएऽऽऽ छेउमै छ नि लालि फूल प्याउली किन हेर्छौ,
जुगै काट्ने मन छ मलाई मन किन फेर्छौ, मन किन फेर्छौ…
एऽऽऽ हे बरै… सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति, हे बरै नलाउ पछि हल्लैको;
हा… हैऽऽऽ सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।

--------------------------

केटा: आउँदा जाँदा देउरालीमा फूल चराउँछु मैले,
आ… होएऽऽऽ आउँदा जाँदा देउरालीमा फूल चराउँछु मैले,
तिम्लाई सम्झी चढाको फूल ओइलिँदैन कहिल्यै, ओइलिँदैन कहिल्यै…
एऽऽऽ हे बरै… सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति, हे बरै नलाउ पछि हल्लैको;
हा… हैऽऽऽ सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।

केटी: जोडी पंक्षी देखेपनी घर मुनिको बोटमा,
आ… होएऽऽऽ जोडी पंक्षी देखेपनी घर मुनिको बोटमा,
तारा खस्दा तिम्रै नाम आउँछ मेरो ओंठमा, आउँछ मेरो ओंठमा…
एऽऽऽ हे बरै… सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति, हे बरै नलाउ पछि हल्लैको;
हा… हैऽऽऽ सालको पातको टपरी हुनी, हे बरै नहुनी सल्लैको;
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।
तिम्रो मायाँ कति छ कति हे बरै नलाउ पछि हल्लैको ।

Day5 - Terraform - plan, refresh, apply, desire, code, tfstat, destroy

 Day5 - Terraform 5-13-2021

day5 - Terraform - plan, refresh, apply, desire, code, tfstat, destroy

notepad a.tf
terrafrom look for .tf extention file and executes


> notepad web.tf
provider "aws" {
  region                  = "ap-south-1"
  profile                 = "default"
}

resource "aws_instance" "webos1" {
  ami           = "ami-010aff33ed5991201"
  instance_type = "t2.micro"
  security_groups =  [ "webport-allow" ]
  key_name = "terraform_key"

  tags = {
    Name = "Web Server by TF"
  }
}

resource "null_resource"  "nullremote1" {

connection {
    type     = "ssh"
    user     = "ec2-user"
    private_key = file("C:/Users/Vimal Daga/Downloads/terraform_key.pem")
    host     = aws_instance.webos1.public_ip
  }

provisioner "remote-exec" {
    inline = [
      "sudo yum  install httpd  -y",
      "sudo  yum  install php  -y",
      "sudo systemctl start httpd",
      "sudo systemctl start httpd"
    ]
  }
}

resource "aws_ebs_volume" "example" {
  availability_zone = aws_instance.webos1.availability_zone
  size              = 1

  tags = {
    Name = "Web Server HD by TF"
  }
}

resource "aws_volume_attachment" "ebs_att" {
  device_name = "/dev/sdc"
  volume_id   = aws_ebs_volume.example.id
  instance_id = aws_instance.webos1.id
  force_detach = true
}

resource "null_resource"  "nullremote2" {

connection {
    type     = "ssh"
    user     = "ec2-user"
    private_key = file("C:/Users/Vimal Daga/Downloads/terraform_key.pem")
    host     = aws_instance.webos1.public_ip
  }

provisioner "remote-exec" {
    inline = [
      "sudo mkfs.ext4 /dev/xvdc",
      "sudo  mount /dev/xvdc  /var/www/html",
    ]
  }
}

resource "null_resource"  "nullremote4" {

connection {
    type     = "ssh"
    user     = "ec2-user"
    private_key = file("C:/Users/Vimal Daga/Downloads/terraform_key.pem")
    host     = aws_instance.webos1.public_ip
  }

provisioner "remote-exec" {
    inline = [
      "sudo yum install git -y",
      "sudo git clone https://github.com/vimallinuxworld13/gitphptest.git   /var/www/html/web"
    ]
  }
}

resource "null_resource"  "nullremote5" {

provisioner "local-exec" {
   command = "chrome http://13.232.50.58/web/index.php"
  }
}

=====================================

break this file

> notepad provider.tf
provider "aws" {
  region: = "ap-south-1"
  profile = "default"
}


> notepad ec2.tf
resource "Aws_instance" "webos1" {
  ami = "amo .."
  instal


tags = {
  Name = web
}



> terraform init

go there and check all the files and download the plugins for the provider such as aws, azure


> attach_block.tf
resource "aws_volume_attachment" "ebs_att" {
  device_name = "/dev/sdc"
  volume_id   = aws_ebs_volume.example.id
  instance_id = aws_instance.webos1.id
  force_detach = true
}


files are read on alphabet order, but TF will automatically handle or manage. This concept is called infering the resource with thier intellegency.
this means, which part to run first and which one to second.

> terraform plan
> tf apply

when you run this code first time, it will create tfstate

there are two state
1. desire state
2. Current state

1. Desire state
whatever you are looking for/want, you write on code - your desire state

2. Current state
What is there right now, or currently running or exist on the system


when you run tr apply, it will go and check if it already exists. if its not there then apply the code.
This concept is called - Idompotence

? tf apply
you will see a message - Infrascture is up to data
if no change is needed.

Login to your aws cloud
- check how many instances running
- check on what instance type is running.

first you run plan and apply (behind the scene plan runs when you run apply)
- when you run plan code, it basically goes and login to aws, retrive all the info and store locally and stores on terraform.tfstat file when is basically the state of the service.
stores all
open and review the file..


> notepad output.tf
output "myip" {
  value = aws_instance.webis1.public_ip
}

> tf apply

you will see the public IP.

open the file terraform.tfstat and search for public_ip and navigate through..


Note: if you use Terraform, always use terraform. do not do automation and manual.

it will make a mess..

any change, you have to make, make sure to modify the code.
say if one of the ec2 instance has issue, they may go to console and manually change the config but its not been updated on code, you will have a problem.


say, lets go to aws console and review the instnce that you have instance type is t2.small

but on your code, you hae t2.micro.

instance_type = "t2.micro"


Desire state is manual t2.small
but code has: automate: t2.micro

> tf apply

our code goes to copy the current state and it will find the conflict.

before apply, use refresh. it will go to cloud and update/referesh the current state. after that, local file is updated terraform.tfstate

> tf refresh

> notepad terraform.tfstat

> tf apply
it will change from small to micro

since your code has micro, it will change

either do everything manual, or everything automation.


Note: Never modify tfstat file manually.


refresh, plan, apply, desire, code, tfstat,  


add null resources
> notepad apache.tf
> tf destroy     # remove all the resources
They go and refresh and update the tfstat file locally.


> tf apply

- apache
- hard disk
- providers

4 resources are going to be applied.

1. Launch the instance
2. ssh -> null -: php apache
3. created storage and attahing the storage

we have one bug here.

lets destroy our infrascture again.

> notepad apache.tf



provisioner "remote-exec" {
    inline = [
      "sudo yum  install httpd  -y",
      "sudo  yum  install php  -y",
      "sudo systemctl start httpd",
      "sudo systemctl start httpd"
    ]
  }
}



file name by default are on lexical order...



apache.tf
resource "null_resource" "nullremote1" {

depends_on = [
  aws_volume_attachment.ebs_att
]

.........
}


google fro terrafrom depends on

meta-arguement

one resource is deepnds on other respurce.



> tf destroy
> tf apply


validate your code
> terraform validate

gives you line number you have issue with



Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...