Thursday, June 10, 2021

RHEL7 - Repurpose RHEL7 machine

 Our one of the physical machine is retired. We have to repurpose it. Had to perform the following tasks.


1. Remove software

2. Rename hostname

3. Change ILO info

4. Update monitoring tools

5. Modify backup

 

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

1. Removed the software

- Since this is a linux physical machine, the software I had to removed came with uninstall script. 

- just ran the script, its done. 

- Remove user/group

- Remove all the files reference to the application

- Delete temp files

 

2. Rename hostname

# hostnamectl - help

 

3. Update mornitoring tools

- If you use nagios, change it or any other tools, go to settings /config and change it

 

3. Change ILO info

- Login to console and reboot your OS

- Press F9 to go to BIOS when the menu is displayed.  

- Select system config

- ILO configuration utility

- Network options

-  Change the hosttname here, it says change the DNS Name: mylxhost

- Click on save and exit

- Update DNS record (either on Windows or linux)

-  Reboot the system

- Login back and click on Security -> SSL Certificate -> Generate CSR

- Go to your cert server: 192.168.10.20/certserv

- Copy the the key (csr) and submit here.   

- Download the cert - issue : 64 base encoded


Imporrt

-> Go back and click on import/copy the downloaded certificate


4. Update the hostname record and backup

- Update your master server database 

- Schedule backup

 

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

 

Change the hostname in RHEL7

There are multiple ways you can change hostname on RHEL7

1. Using hostname control - hostnamectl command
2. using NetworkManager - nmcli command
3. useing NetworkManager text user interface - nmtui command
4. Modify /etc/hostname file and reboot the machine

1. Using hostname control - hostnamectl command
# hostnamectl -h
# hostnamectl status
# hostnamectl set-hostname myhost01
# hostnamectl

2. using NetworkManager - nmcli command
# nmcli -h
# nmcli general hostname
# nmcli general hostname myhost01
# service systemd-hostnamed restart
# hostname

3. using NetworkManager TUI - nmtui command
Here, you type the command nmtui at the command prompt
- select the option "set the hostname" and press enter
- Type your hostname here and press enter
- change hostname nmtui
- Confirm the change
- and quit the screen
- Restart the systemd-hostnamed service
# systemctl status systemd-hostnamed
# hostnamectl

4. Modify /etc/hostname file and reboot the machine
1. Edit the hostfile and make the change
# vi /etc/hostname.

2. Reboot the machine and verify it
# shutdown -r now
# hostnamectl; hostname

Monday, June 7, 2021

Install HPE Foundation on HPE machine

 How to set up HPE Foundation 2.4.2 repository

1. Copy the software
# mkdir /opt/foundation
# mount -t iso9660 /var/tmp/hpe-foundation-2.4.2-cd1-media-rhel77-x86_64.iso /mnt
# cp -Rvp /mnt/* /opt/foundation
# umount /mnt

2. Set up repo
# cat <<EOF > /etc/yum.repos.d/foundation-2.4.2_.repo
[Foundation-Repo]
name = HPE Foundaton 2.4.2 - \$basearch
baseurl = file:///opt/foundation/RPMS
enabled=0
gpgcheck = 1
gpgkey = file:///opt/foundation/RPM-GPG-KEY-hpe
     file:///opt/foundation/RPM-GPG-KEY-sgi
EOF

3. Perform the update
# yum --enablerepo=foundation-2.4.2-repo check-update

Friday, June 4, 2021

Day12 - Terraform workspace, regex

 Day12 - Terraform - 06042021

Workspace, regex


> mkdir wp; cd wp

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


variable "type" {
 type = map
 default = {
  dev = "t2.micro"
  test = "t2.small"
  prod = "t2.large"
  }
}
resource "aws_instance" "webos1" {
    ami = "ami..."
    instance_type = "t2.micro"
      security_group     = [ "webport-allow" ]
    key_name = "terraform_key"

    tags = {
       Name = "We server by TF"
    }
}

*/
output "o1" {
  value = terraform.workspace
}

get help
> terraform workspace -h
> tf worksapce list
> tf workspace show





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


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


variable "type" {
 type = map
 default = {
  dev = "t2.micro"
  test = "t2.small"
  prod = "t2.large"
  }
}
resource "aws_instance" "webos1" {
    ami = "ami..."
    instance_type = lookup (var.type, terraform.worspace)
 
    tags = {
       Name = "We server by TF"
    }
}

*/
output "o1" {
  value = terraform.workspace
}


> tf worspace show
> tf apply
> tf workspace -h
>

chnage your env
> tf workspace select dev
> tf worksapce show
> tf apply    @ it will automatically understands you are on dev env.

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

Google: terraform regex

regex function

go through the example ..

say you are retriving some values
http://<IP>:<port/path/file.html

- create pattern, format
regex(pattern, format)


regex{}
get only characters
> terraform console
regex("[a-z]+", "24442,5323423basjkdhfsdh4")


do more function

replace function

> replace("1 + 2 + 3", "+", "-")
1 - 2- 3

> replace (hello world". "/w.*d/", "everybody")

There are lots of functions and go through these documents..

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

FullStack
workspace
- Dev  -> GCP
- Test -> AZ
- Prod -> AWS

EC2 - web server
    - DB RDS server

Azure
- VM instances
- Launch database service


google - multicould strategy example

FE (WordPress)    -> GCP      
DB (MySql)     -> AWS - RDS

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

google teraform data sources
- to retirve partucular value
and use on other resource..


resource "aws_instance" "app" {
 ami = "$(data.aws_ami.app_ami.id}"
 instance_type = "t2.micro"
}


Terraform commands

 Terraform Commands

refresh - query infrascture provider to get the current state     - State
plan    - Create an execution plan/ preview of what is going to happen    - Plan
apply    - Execute the plan/applies the configuration file        - Apply
destroy    - Destroy the resource/infrascture/ removes one by one in an order. Revert back everything created will be destroyed.
-------------------------
> terraform plan command

How plan creates the plan
ansible core evaluates
- your code - terraform configuration code
- tfstate file

to create the execution plan and decides what needs to be done.
So, it will determines what actions are required to achive the desire state.


it basically checks the file you created that is your desire state (your code) and compares with the existing set up and figures it out what changes or adjustments need to be made in order to meet the desire state.

For eg, change an instance type, create a new instance or user ..

a sample code
-------------

# AWS Provider
provider "aws" {
  region = "us-east-1"
  profile = "default"
}

# resource
resource "aws-instance" "web" {
 ami = "ami...." "web" {
 instance_type = "t3.small"

 tags = {
  Name = "Test"
 }
}

# Create VPC
resource "aws_vpc" "wnet" {
 cidr
}



$ cat storage-db-55a.inv | grep -E "\s+Trya.*\(SAS\)" | awk '{print "%20s| %s\n", $8,$15}' | sort | uniq -c


Pulumi vs terraform vs CrossPlane

 https://www.pulumi.com/docs/intro/vs/terraform/

 I see power on pulumi if you are good on coding


What is Terraform?

Terraform is a popular open-source IaC tool for building, modifying, and versioning virtual infrastructure.

The tool is used with all major cloud providers. Terraform is used to provision everything from low-level components, such as storage and networking, to high-end resources such as DNS entries. Building environments with Terraform is user-friendly and efficient. Users can also manage multi-cloud or multi offering environments with this tool.

Terraform is a declarative IaC tool. Users write configuration files to describe the needed components to Terraform. The tool then generates a plan describing the required steps to reach the desired state. If the user agrees with the outline, Terraform executes the configuration and builds the desired infrastructure.

What is Pulumi?

Pulumi is an open-source IaC tool for designing, deploying and managing resources on cloud infrastructure. The tool supports numerous public, private, and hybrid cloud providers, such as AWS, Azure, Google Cloud, Kubernetes, phoenixNAP Bare Metal Cloud, and OpenStack.

Pulumi is used to create traditional infrastructure elements such as virtual machines, networks, and databases. The tool is also used for designing modern cloud components, including containers, clusters, and serverless functions.

While Pulumi features imperative programming languages, use the tool for declarative IaC. The user defines the desired state of the infrastructure, and Pulumi builds up the requested resources.

Pulumi allows developers to use general-purpose languages such as JavaScript, TypeScript, .Net, Python, and Go. Familiar languages allow familiar constructs, such as for loops, functions, and classes. All these functionalities are available with HCL too, but their use requires workarounds that complicate the syntax.

 https://www.youtube.com/watch?v=RaoKcJGchKM

What is Crossplane?

 Crossplane is an open source Kubernetes add-on that enables platform teams to assemble infrastructure from multiple vendors, and expose higher level self-service APIs for application teams to consume, without having to write any code.

No more about CrossPlane.. 

Pulumi vs. Terraform

Terraform and Pulumi hold a lot of similarities, but they differ in a few key ways. This page helps provide a rundown of the differences. First, Pulumi is like Terraform, in that you create, deploy, and manage infrastructure as code on any cloud. But where Terraform requires the use of a custom programming language, Pulumi allows you to use familiar general purpose languages and tools to accomplish the same goals. Like Terraform, Pulumi is open source on GitHub and is free to use.

Both Terraform and Pulumi support many cloud providers, including AWS, Azure, and Google Cloud, plus other services like CloudFlare, Digital Ocean, and more. Thanks to integration with Terraform providers, Pulumi is able to support a superset of the providers that Terraform currently offers.

Here is a summary of the key differences between Pulumi and Terraform:

ComponentPulumiTerraform
Language SupportPython, TypeScript, JavaScript, Go, C#, F#Hashicorp Configuration Language (HCL)
State ManagementManaged through Pulumi Service by default, self-managed options availableSelf-managed by default, managed SaaS offering available
Provider SupportNative cloud providers with 100% same-day resource coverage plus Terraform-based providers for additional coverageSupport across multiple IaaS, SaaS, and PaaS providers
OSS LicenseApache License 2.0Mozilla Public License 2.0

If you have Terraform HCL that you would like to convert to Pulumi, see Converting Terraform HCL to Pulumi in our Adopting Pulumi user guide.

The following sections go into further detail on the differences between Pulumi and Terraform.

Language Support

Terraform requires that you and your team write programs in a custom domain-specific-language (DSL) called HashiCorp Configuration Language (HCL). In contrast, Pulumi lets you use programming languages like Python, Go, JavaScript, TypeScript, and C#. Because of the use of familiar languages, you get familiar constructs like for loops, functions, and classes. This significantly improves the ability to cut down on boilerplate and enforce best practices. Instead of creating a new ecosystem of modules and sharing, Pulumi lets you leverage existing package management tools and techniques.

For more information on the languages that Pulumi supports, see Languages.

State Management

The Terraform engine takes care of provisioning and updating resources. With Pulumi, you use general purpose languages to express desired state, and Pulumi’s engine similarly gives you diffs and a way to robustly update your infrastructure.

By default, Terraform requires that you manage concurrency and state manually, by way of its “state files.” Pulumi, in contrast, uses the free Pulumi Service to eliminate these concerns. This makes getting started with Pulumi, and operationalizing it in a team setting, much easier. For advanced use cases, it is possible to use Pulumi without the service, which works a lot more like Terraform, but it requires you to manage state and concurrency issues. Pulumi errs on the side of ease-of-use.

For more information on how Pulumi manages state or how to use different backends, see State and Backends.

Provider Support

Pulumi has deep support for cloud native technologies, like Kubernetes, and supports advanced deployment scenarios that cannot be expressed with Terraform. This includes Prometheus-based canaries, automatic Envoy sidecar injection, and more. Pulumi is a proud member of the Cloud Native Computing Foundation (CNCF).

Using Terraform Providers

Pulumi is able to adapt any Terraform Provider for use with Pulumi, enabling management of any infrastructure supported by the Terraform Providers ecosystem using Pulumi programs.

Indeed, some of Pulumi’s most interesting providers have been created this way, delivering access to robust, tried-and-true infrastructure management. The Terraform Providers ecosystem is mature and healthy, and enjoys contributions from many cloud and infrastructure leaders across the industry, ourselves included.

Most Pulumi users don’t need to know about this detail, however we are proud to be building on the work of others, and contributing our own open source back to this vibrant ecosystem, and thought you should know.

In the event you’d like to add new providers, or understand how this integration works, check out the Pulumi Terraform bridge repo. This bridge is fully open source and makes it easy to create new Pulumi providers out of existing Terraform Providers.

Converting From Terraform

Pulumi offers a tool, tf2pulumi, that converts Terraform HashiCorp Configuration Language to Pulumi. It is open source on GitHub, and works for most projects we have come across; if you run into a snag, Issues and Pull Requests are welcome!

To learn more, see Converting Terraform HCL to Pulumi in our Adopting Pulumi user guide.

For an example on how to do this conversion, see our article, From Terraform to Infrastructure as Software.

Using Pulumi and Terraform Side-by-Side

Pulumi supports consuming local or remote Terraform state from your Pulumi programs. This helps with incremental adoption, whereby you continue managing a subset of your infrastructure with Terraform, while you incrementally move to Pulumi.

For example, maybe you would like to keep your VPC and low-level network definitions written in Terraform so as to avoid any disruption, or maybe because some of the team would like to stay on Terraform for now and make a shift in the future. Using the state reference support described previously, you can author higher-level infrastructure in Pulumi that consumes the Terraform-provisioned VPC information (such as the VPC ID, Subnet IDs, etc.), making the co-existence of Pulumi and Terraform easy to automate.

To learn more, see Referencing Terraform State in our Adopting Pulumi user guide.

OSS License

Terraform uses the weak copyleft Mozilla Public License 2.0. Conversely, Pulumi open-source projects use the permissive and business-friendly Apache License 2.0. This includes the core Pulumi repo, all of the open-source Pulumi resource providers (such as the Azure Native provider), conversion utilities like tf2pulumi, and other useful projects.

 

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

 https://phoenixnap.com/blog/pulumi-vs-terraform

Pulumi vs Terraform: Comparing Key Differences

 

1. Unlike Terraform, Pulumi Does Not Have a DSL

2. Different Types of State Management

3. Pulumi Offers More Code Versatility

4. Terraform is Better at Structuring Large Projects

5. Terraform Provides Better State File Troubleshooting

6. Pulumi Offers Better Built-In Testing

7. Terraform Has Better Documentation and a Bigger Community

8. Deploying to the Cloud

 

 

 

 

 

 

 

 

 

Thursday, June 3, 2021

Terraform - Remote State Management

 Terraform - 6-03-2021

Today's topic
Remote state management
- using S3
- Lock state - DynamoDB



mkdir ws/s; cd ws/s



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

google:- terraforom ec2 resource

go to instance adn get the resorce

resource "aws-instance" "web" {
  ami = "ami-....."
  instance_type = "t3.micro"    # you can change this and run apply

  tags = {
    Name = "Hello"
  }

}


> tf init


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

tfstate file - stores current state of the project not the desire
the desire state will be on our program file that we just wrote

if you work alone, its ok, but what if multiple folks working?



> tf apply


What happens if one person want to change something and other person also want to change at the same time.

-> whoever start the apply command first, tfstate file will be locked by default and second guy will have to wait..


$ cat s.tf
provider "aws" {
  region = "ap-south-1"
  profile = "default"
}

resource "aws-instance" "web" {
  ami = "ami-....."
  instance_type = "t2.small"    # you can change this and run apply

  tags = {
    Name = "Hello"
  }

}


> tf apply

tfstate file will be changed to .terraform.tfstate.lock.info

until the job is completed, other person can not run the apply command.


if everyone is working on their own laptop, code is stored on github.

two employe have their own tfstate file.

if two developers working on same project, then don't maintain two state file on common project.

We don't maintain it locally. We will store it on centralized storage such as nfs. in our case its going to be s3.

You can do everything from your local laptop but we will move the tfstate file to s3 which is going to be a centralised shared location.

How do we manage state file remotely?
How do you manage the lock?

-> We will maintain the tfstate file. s3 is object storage.
- lets go to aws console -> s3 and create a folder which is called bucket
a. Create a bucket :
  - click on create bucket - name it
or

create using code.

> mkdir s3; cd s3

search resource s3 bucket
also look for versioning
 -someone may delete bucket or a file.
 - we don't want any one to delete it. -> look for lifecycle

google for lifecycle prevent_destroy = true


> notepad s3.tf

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

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-bucket..."

  # state file keep on chaging, so its a good idea to versioning. if someone makes mistakes, you can revert it back.

lifecycle {
  prevent_destroy = true
}

  versioning = {
    enabled = true
  }

}


> tf apply -auto-approve

Note: bucket need to be unique.

now, we have to upload the state file.

> mkdir remotestate; cd remotestate
> notepad r.tf


Now, we will create a new project and we want to create a statefile remotely.
We want the state file to be managed remotely

google: terraform remote state
review the document.

backend ..



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

resource "aws_s3_bucket" "b" {
  bucket = "my-tf-bucket..."

lifecycle {
  prevent_destroy = true
}

  versioning = {
    enabled = true
  }

}

terraform {
  backend "s3"
  bucket = "my-tf-bucket..."
  key = "my.tfstate"
  region = "us-east-1"
  }
}

}


> tf init    # review the message you see on the screen

> notepad e.tf


resource "aws-instance" "web" {
  ami         = "ami-....."
  instance_type = "t2.small"

  tags = {
    Name = "Hello"
  }

}


> tf apply


tfstate file will be created on s3 bucket.
any change will be updated on remove server/storage.

go to s3, you will see file is uploaded

this does not resolve the chanllenge of lock.

for locking support, they suggest to use dynamo DB.

We are going to create a table on dynamoDB.


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

Go to aws console and DynamoDB manually or use terraform

on teffarom web page, search for: dynamodb table

dynamoDB state locking - search on tf.com site

> mkdir ddb; cd ddb
> notepad d.tf


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

resource "aws_dunamodb_table" "basic-dynaodb-table" {
 name        = "tfstate-lock-table"
 read_capacity    = 5
 write_capacity = 5
 hash_key     = "LockID"

 attribute {
  name = "LockID"
  type = "S"
  }
}


> tf apply

enter a value: yes

it will create a dynamoDB table. go to the console and verify it.

you will see the table with primary key.

now, localing state will be managed by dynamoDB table that we just created.




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

terraform {
  backend "s3" {
  bucket     = "my-tf-bucket..."
  key         = "my.tfstate"
  region     = "us-east-1"

dynamodb_table = "tfstate-lock-table"
  }

}

> tf init
> tf apply

this time, if other team member try to use the state file, first member can execute the program but had to wait the second one.

if other member tries to run, gets an error.

This is how you can lock the locking state.
This is how you can colaborate with your team member.

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

registry.terrafrom.io/providers/hashicorp/azurerm/latest/docs#example-usage


how to use azure>
go to registry-> azure -> document -> authentication
authenticate using cli or locally -> find the authentication methid, provider.

once you authenticate, you can launch some resource group.

create VPC, or instances, containers...

Lets see other member wants the check the state

> tf state

you can pull your state
> tf state pull
you will see what is current state going on..



RHEL7 - How to check changelog of RPM packages

 How to check change log of RPM packages on CentOS/RHEL

Read the changelog of RPM packages on RHEL7
# rpm -qa | grep httpd
# rpm -q --changelog httpd

or
# rpm -qp --changelog [/path to the rpm package]

Import public key

# rpm -qa | grep gpg
# rpm --import mykey-2048.gpg

 

 

 

 

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

 

rpm: Find out what files are in my rpm package

Use following syntax to list the files for already INSTALLED package:
rpm -ql package-name

Use following syntax to list the files for RPM package:
rpm -qlp package.rpm

Type the following command to list the files for gnupg*.rpm package file:
$ rpm -qlp rpm -qlp gnupg-1.4.5-1.i386.rpm


In this example, list files in a installed package called ksh:
$ rpm -ql ksh


See the files installed by a yum package named bash:
repoquery --list bash
repoquery -l '*bash*'

Syntax
repoquery -l {package-name-here}
repoquery -q -l {package-name-here}
repoquery -q -l --plugins {package-name-here}
repoquery -q -l --plugins *{package-name-here}*
repoquery -q -l --plugins http
repoquery -q -l --plugins ksh

here,
    -l : List files in package
    -q : For rpmquery compatibility (not needed)
    --plugins : Enable plug-ins support

List the contents of a package using yum command

1. Open the terminal bash shell and type:
$ sudo yum install yum-utils

2. See the files installed by a yum package named bash:
$ repoquery --list bash
$ repoquery -l '*bash*'



https://www.cyberciti.biz/faq/howto-list-find-files-in-rpm-package/

 

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. ...