Pages

Friday, April 14, 2023

Installing Brew in Mac

Homebrew is a free and open-source package manager for macOS that simplifies the process of installing, updating, and managing software packages on your Mac. It allows you to easily install and manage a wide range of software packages, libraries, and tools that are not included in macOS by default.
Homebrew uses a command-line interface to install packages and dependencies, which means that you can easily manage and customize your software installations using simple commands in the Terminal.
Some of the benefits of using Homebrew on your Mac include:
  • Easy installation of software packages and dependencies
  • Automatic updates of installed packages
  • Uninstallation of packages and dependencies
  • Ability to customize software installations with different options and versions
  • Access to a large and active community of developers who contribute to Homebrew's package repository
Following are commands to install the brew and add it to CLI.

xcode-select --install
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 
Following will be at the end of the installation, Copy and run that in the Mac CLI. 
  (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/<Username>/.zprofile\n    eval "$(/opt/homebrew/bin/brew shellenv)"


xcode-select --install is a command that installs the command-line tools for Xcode on your Mac. Xcode is a development environment for macOS that provides tools for developing software for macOS, iOS, watchOS, and tvOS. The command-line tools for Xcode include a variety of tools and libraries that are necessary for building and compiling software on your Mac, even if you are not using Xcode itself.
Running xcode-select --install will open a dialog box that prompts you to install the command-line tools for Xcode. This may take a few minutes to complete, depending on your internet connection speed.

The command /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" installs Homebrew on your Mac. Homebrew is a package manager that allows you to easily install and manage software packages and libraries on your Mac.
The installation script for Homebrew will download and install the necessary files and dependencies for Homebrew, and will configure your system to use Homebrew as your default package manager.

The last command (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/<Username>/.zprofile\n eval "$(/opt/homebrew/bin/brew shellenv)" adds the necessary configuration to your .zprofile file to ensure that Homebrew is properly configured on your system. This command adds a line to your .zprofile file that tells your terminal to evaluate the output of the brew shellenv command, which sets up your environment variables to use Homebrew. This ensures that when you open a new terminal session, your system is properly configured to use Homebrew.

Thursday, April 13, 2023

Troubleshooting Ansible and VMware: Resolving 'Failed to import PyVmomi library' Error

When working with Ansible and VMware, you may encounter an error message similar to the following:


msg: Failed to import the required Python library (PyVmomi) on <hostname>'s Python <path/to/python>. Please read the module documentation and install it in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter.

This error message indicates that Ansible is unable to import the required Python library PyVmomi when running a playbook. This library is required to interact with VMware virtualization products.

To resolve this issue, you should first ensure that the PyVmomi library is installed in the appropriate location. You can use pip to install the library:

pip install pyvmomi

Next, you should verify that Ansible is using the correct version of Python and pip. The error message may indicate that Ansible is using the wrong Python interpreter or version of pip. You can check which version of Python Ansible is using by running the ansible --version command and looking for the ansible_python_interpreter line in the output. If the interpreter is incorrect, you can set the correct interpreter path using the ansible_python_interpreter variable in your playbook or in your inventory file.
It's also important to ensure that you are using the correct version of pip to install packages. If you have multiple versions of Python installed, you may also have multiple versions of pip. You can check the version of pip you are using with the pip --version command. If you are using the wrong version of pip, you can switch to the correct version using the appropriate command for your operating system.

If the issue persists, you may need to uninstall any conflicting libraries or packages, such as pyvim, and try reinstalling PyVmomi to ensure that there are no conflicts or version mismatches.

By following these steps, you can resolve the Failed to import the required Python library error message and ensure that Ansible is using the correct Python interpreter and version of pip for installing packages.

Wednesday, April 12, 2023

Generalizing ubuntu for vmware

When you clone a virtual machine in VMware, the new machine is an exact copy of the original machine, including the network settings. This means that the new machine will have the same IP address, MAC address, and other network settings as the original machine. This can cause network conflicts and other issues, especially if you are running multiple clones of the same machine on the same network.
    
To avoid this issue, you need to ensure that each clone of the machine has a unique network configuration. One way to do this is to delete the machine-id file, which is a unique identifier for the machine. When the machine boots up, it generates a new machine-id based on its hardware configuration, which will result in a unique network configuration.

The command rm -rf /var/log/* removes all logs from the /var/log directory, which can help to free up disk space and reduce clutter. However, it is important to note that this command will permanently delete all log files, which can make troubleshooting more difficult if there are issues with the system.

To delete the value in the machine-id file, you can use the following command:

echo "" > /etc/machine-id

** Don't rm -rf the machine-id file, the system might get stuck at the start. 

This will clear the value in the file, effectively resetting the machine ID and generating a new ID on boot.

In addition to deleting the machine-id file, you may also want to clear the SSH keys and other sensitive information from the virtual machine. This can help to ensure that each clone of the machine is unique and secure.


Tuesday, April 11, 2023

Using Azure Lighthouse for Monitoring Other Tenant.

Azure Lighthouse is a service provided by Microsoft Azure that allows service providers to manage multiple customers’ Azure services from a single control plane. It provides a centralized portal to manage multiple Azure tenants, customers or subscriptions, giving the service provider a single view of all Azure resources across different customer environments. Azure Lighthouse provides several features including delegated resource management, multi-tenant management, and cross-tenant management, which help service providers to manage resources across their entire customer base in a secure and efficient manner. It simplifies and streamlines the management of Azure services, provides greater visibility into customers’ environments, and enables service providers to deliver better services to their customers.


In Short, we give access to a subscription or resource to a User/Group in another tenant with specific Roles. 


Sample ARM Template for adding a Customer account to Service Providers Lighthouse. 

"managedByTenantId": "a86bc255-XXXX-CCCC-VVVV-51fba84872aa"

Above is the Tenant ID of the Managed Services Provider. 

"defaultValue": "XXXXXXXXXXXXXXXXXXXXXXX"

Above is the Name of the Offering.

defaultValue": "YYYYYYYYYYYYYYYYYYYYYYYYYY"

Above is the Description of the Offering.

"principalId": "9d45cb5e-4682-4a4d-b54a-a89e3fa7bc84",

Above is the Object ID of the User or the Group we are selecting for this Offering.

"roleDefinitionId": "acdd72a7-3385-48ef-bd42-f606fba81ae7",

Above is the ID of the Role we are selecting.

"principalIdDisplayName": "Azure Reader Access"

Above is the Name of the Role we are selecting.


Sample ARM

{
"$schema": "https://schema.management.azure.com/schemas/2019-08-01/subscriptionDeploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"mspOfferName": {
"type": "string",
"metadata": {
"description": "Specify a unique name for your offer"
},
"defaultValue": "XXXXXXXXXXXXXXXXXXXXXXX"
},
"mspOfferDescription": {
"type": "string",
"metadata": {
"description": "Name of the Managed Service Provider offering"
},
"defaultValue": "YYYYYYYYYYYYYYYYYYYYYYYYYY"
}
},
"variables": {
"mspRegistrationName": "[guid(parameters('mspOfferName'))]",
"mspAssignmentName": "[guid(parameters('mspOfferName'))]",
"managedByTenantId": "a86bc255-XXXX-CCCC-VVVV-51fba84872aa",
"authorizations": [
{
"principalId": "9d45cb5e-AAAA-BBBB-CCCCC-DDDDDDDD",
"roleDefinitionId": "acdd72a7-3385-48ef-bd42-f606fba81ae7",
"principalIdDisplayName": "Azure Reader Access"
},
{
"principalId": "9d45cb5e-AAAA-BBBB-CCCCC-DDDDDDDD",
"roleDefinitionId": "cfd33db0-3dd1-45e3-aa9d-cdbdf3b6f24e",
"principalIdDisplayName": "Support Request Contributor"
}
]
},
"resources": [
{
"type": "Microsoft.ManagedServices/registrationDefinitions",
"apiVersion": "2020-02-01-preview",
"name": "[variables('mspRegistrationName')]",
"properties": {
"registrationDefinitionName": "[parameters('mspOfferName')]",
"description": "[parameters('mspOfferDescription')]",
"managedByTenantId": "[variables('managedByTenantId')]",
"authorizations": "[variables('authorizations')]"
}
},
{
"type": "Microsoft.ManagedServices/registrationAssignments",
"apiVersion": "2020-02-01-preview",
"name": "[variables('mspAssignmentName')]",
"dependsOn": [
"[resourceId('Microsoft.ManagedServices/registrationDefinitions/', variables('mspRegistrationName'))]"
],
"properties": {
"registrationDefinitionId": "[resourceId('Microsoft.ManagedServices/registrationDefinitions/', variables('mspRegistrationName'))]"
}
}
],
"outputs": {
"mspOfferName": {
"type": "string",
"value": "[concat('Managed by', ' ', parameters('mspOfferName'))]"
},
"authorizations": {
"type": "array",
"value": "[variables('authorizations')]"
}
}
}

Monday, April 10, 2023

NextCloud Setup with Docker

One of the most commonly used self-hosted alternatives for cloud storages. Now it's easy to deploy with dockers. Following docker file and Nginx configuration can be used to deploy the nextcloud application behind the Nginx proxy server with SSL termination. 
we can bring up and bring down the containers with the following commands

docket-compose up -f
docker-compose down

===========

version: '2'
#volumes:
#  nextcloud: /root/nextcloud/ncdata
#  db: /root/nextcloud/mysql
services:
  db:
    image: mariadb:10.5
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - /root/nextcloud/mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=XXXXXXXXX
      - MYSQL_PASSWORD=XXXXXXXX
      - MYSQL_DATABASE=XXXXXXXX
      - MYSQL_USER=XXXXXXXX
  app:
    image: nextcloud
    restart: always
    links:
      - db
    volumes:
      - /root/nextcloud/ncdata:/var/www/html
    environment:
      - MYSQL_PASSWORD=XXXXXXXX
      - MYSQL_DATABASE=XXXXXXXX
      - MYSQL_USER=XXXXXXXX
      - MYSQL_HOST=XXXXXXXX
      - NEXTCLOUD_TRUSTED_DOMAINS=abc.xyz.aa
      - OVERWRITEHOST=abc.xyz.aa:XXXX
      - OVERWRITEPROTOCOL=https
        
  web:
       image: nginx
       restart: always
       ports:
         - 8082:8080
       links:
         - app
       volumes:
         - /root/nextcloud/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
         - /root/nextcloud/cert:/etc/cert
===========
Nginx Configuration file
===========

server {
  listen 80;
  server_name abc.xyz.aa;
  return 301 https://$server_name:8080$request_uri;
  add_header X-Content-Type-Options              "nosniff";
}
server {
  listen 8080 ssl;
  server_name abc.xyz.aa;
  ssl_certificate /etc/cert/abc.xyz.aa.crt;
  ssl_certificate_key /etc/cert/abc.xyz.aa.key;
  ssl_prefer_server_ciphers on;
  location / {
  proxy_pass http://app;
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
 }

===========




Kubernetes(k8s) Sample Commands - 02

Following are a few of the  kubectl commands for managing Kubernetes clusters:

  • kubectl get nodes -o=jsonpath='{XX}'
    • This command retrieves information about the nodes in the cluster using the jsonpath output format. Replace {XX} with the desired path.
  • kubectl get nodes -o=custom-columns=<Column name>
    • This command retrieves information about the nodes in the cluster using custom columns output format. Replace <Column name> with the desired column name
  • --sort-by=
    • This option is used to sort the output based on a specified field.
  • kubectl get node node01 -o json > /opt/outputs/node01.json
    • This command retrieves information about a specific node and saves it as a JSON file.
  • kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /opt/outputs/nodes_os.txt
    • This command retrieves the OS image of all the nodes in the cluster and saves it in a text file.
  • kubectl config view --kubeconfig=my-kube-config -o jsonpath="{.users[*].name}" > /opt/outputs/users.txt
    • This command retrieves the names of all users in the kubeconfig file and saves it in a text file.
  • kubectl get pv --sort-by=.spec.capacity.storage > /opt/outputs/storage-capacity-sorted.txt
    • This command retrieves the capacity of all persistent volumes and sorts the output by storage capacity.
  • kubectl config view --kubeconfig=my-kube-config -o jsonpath="{.contexts[?(@.context.user=='aws-user')].name}" > /opt/outputs/aws-context-name
    • This command retrieves the context name for a specific user in the kubeconfig file.
  • kubectl run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup nginx-resolver-service
    • This command creates a pod named test-nslookup and runs a DNS lookup on nginx-resolver-service.
  • kubectl run test-nslookup --image=busybox:1.28 --rm -it --restart=Never -- nslookup nginx-resolver-service > /root/CKA/nginx.svc
    • This command creates a pod named test-nslookup and redirects the output of the DNS lookup to a file.
  • K get nodes -o jason | jq -c paths |grep type
    • This command retrieves the paths of all fields in the node objects in the cluster that contain the word "type".
  • kubectl create deployment --image=nginx nginx --replicas=4 --dry-run=client -o yaml > nginx-deployment.yaml
    • This command creates a deployment named nginx with 4 replicas and saves the deployment manifest as a YAML file. The --dry-run=client flag is used to simulate the deployment without actually creating it.