Solved : Vagrant failed to initialize at a very early stage powershell error

If you are using Vagrant on Ubuntu and encounter any errors related to the Powershell executable, there is no need to panic. This is a very common problem and easy to solve. Here is a simple guide to resolve the “No Powershell executable found in available PATH” error.

Problem:

When you run vagrant status, you may see something like this:

bash
root@cloudvedas:~# vagrant status
Vagrant failed to initialize at a very early stage:
Failed to locate the powershell executable on the available PATH. Please
ensure powershell is installed and available on the local PATH, then
run the command again.

Basically, Vagrant can't find Powershell in your system PATH.

Solution: Add Powershell to PATH

To fix this issue, you need to add the Powershell executable to your system's PATH. Here's how to do this in Ubuntu:

  1. Open Terminal: First of all, open Terminal.

  2. Update your PATH: Run the following command to add the Powershell executable to your PATH.

    bash
    PATH='${PATH}:/mnt/c/Windows/System32/WindowsPowerShell/v1.0'

    This command simply adds the Powershell directory to your existing PATH variable.

  3. Check your PATH: Verify that the PATH update is working by running:

    bash
    echo $PATH

    You should see /mnt/c/Windows/System32/WindowsPowerShell/v1.0 in the output.

  4. Run Vagrant again: Try running the Vagrant command again.

    bash
    vagrant status

Summary

Adding the Powershell path to your system's PATH variable will fix the error, allowing you to use Vagrant without any issues. This way, Vagrant can find the Powershell executable it needs to function properly.

If the issue persists, check the paths you added and make sure that Powershell is installed correctly on your system.

Python: difference between list and tuple with examples



Lists and tuples both are used to store data in a sequence in Python. Lists are enclosed in square brackets [ ], whereas tuples are enclosed in parentheses ( ).

Here is an example of creating a list in Python:

cv_list = [1, 2, 3, 4, 5]


And here is an example of creating a tuple in Python:


cv_tuple = (1, 2, 3, 4, 5)


To access elements in a list or tuple, you use indexing and slicing. The first element in a list or tuple has an index of 0.

Here is an example of indexing in a list:


print(cv_list[0]) # Output: 1


And here is an example of indexing in a tuple:


print(cv_tuple[0]) # Output: 1


You can also slice a list or tuple to access a range of elements. To slice a list or tuple, you specify the start index and end index separated by a colon :.

Here is an example of slicing a list:


print(cv_list[1:3]) # Output: [2, 3]


And here is an example of slicing a tuple:

print(cv_tuple[1:3]) # Output: (2, 3)


In summary, lists and tuples are both useful data structures in Python, but they have some fundamental differences. Lists are mutable, while tuples are immutable. Lists are used when you need to add, remove, or change elements, while tuples are used when you need to store a collection of elements that won't change. Understanding the differences between these two data structures will help you make the right choice for your program.

How to prepare for Certified Kubernetes Administrator exam

Certified Kubernetes Administrator exam preparation

Hello everyone I have recently cleared the Certified Kubernetes Administrator (CKA) exam by Cloud Native Computing Foundation (CNCF), in collaboration with The Linux Foundation.

In this blog I will share the strategy I used to prepare for the exam and the important tips you should remember while you are actually giving the exam.

My CKA exam was on Kubernetes 1.22 version which is the latest exam version as of 21-Oct-21. You can see broad level domains tested in this exam here .

Solved : How to zip directories in Linux


In this post we will see how you can use zip command in Linux to compress directories and files and unzip them. zip is also very useful if you have to further uncompress the files on windows machine as by default windows allows you to open zip files without installing any extra program.

First let's install zip. Below we will show installation instruction for both Ubuntu and Redhat linux/CentOS.

Ubuntu :

Update the package repo:

root@CloudVedas:~# sudo apt-get update

Now let's install zip and unzip packages:

sudo apt-get install zip unzip -y


RHEL/CentOS:

Update the package repo:

root@CloudVedas:~# sudo yum makecache

Install the zip and unzip packages

root@CloudVedas:~# sudo yum install zip unzip


Once the zip and unzip packages are installed we can now see their usage.

The basic syntax of the zip command is below:

zip -r <output_file>.zip  <dir1> <dir2> ... <dirn>

Let's see some examples :

We will zip three directories

root@CloudVedas:~# zip -r finaldir.zip dir1 dir2 dir3

  adding: dir1/ (stored 0%)

  adding: dir1/test11 (stored 0%)

  adding: dir1/test13 (stored 0%)

  adding: dir1/tet12 (stored 0%)

  adding: dir2/ (stored 0%)

  adding: dir2/test21 (stored 0%)

  adding: dir2/test22 (stored 0%)

  adding: dir2/test23 (stored 0%)

  adding: dir3/ (stored 0%)

  adding: dir3/test31 (stored 0%)

  adding: dir3/test32 (stored 0%)

  adding: dir3/test33 (stored 0%)

root@CloudVedas:~#

When we list the contents we can see our zipped file finaldir.zip .

root@CloudVedas:~# ls -lrth

total 4.0K

drwxr-xr-x 1 root root 4.0K Aug 29 13:54 dir1

drwxr-xr-x 1 root root 4.0K Aug 29 13:54 dir2

drwxr-xr-x 1 root root 4.0K Aug 29 13:54 dir3

-rw-r--r-- 1 root root 1.8K Aug 29 13:55 finaldir.zip

root@CloudVedas:~#


You can also zip all the directories in the present working directory using this simple bash script.

for dir in $(ls -d */); do zip script_archive.zip $dir; done 


View contents of a zip file 

If you want to see the contents of a zip file without unzipping it you can use either vi or vim .

root@CloudVedas:~# vim finaldir.zip

or

root@CloudVedas:~# vi finaldir.zip

With the above commands you can easily see the list of files and directories inside the zip.


unzip

Now let's see how you can unzip a file. Be careful when you are unzipping a file with out any extra options as it will overwrite the existing contents if same name exist. Best is to unzip the file in a different directory and then copy the required files and directories as needed in the destination folder.

root@CloudVedas:~/unziptest# unzip finaldir.zip

Archive:  finaldir.zip

   creating: dir1/

 extracting: dir1/test11

 extracting: dir1/test13

 extracting: dir1/tet12

   creating: dir2/

 extracting: dir2/test21

 extracting: dir2/test22

 extracting: dir2/test23

   creating: dir3/

 extracting: dir3/test31

 extracting: dir3/test32

 extracting: dir3/test33

root@CloudVedas:~/unziptest# ls

dir1  dir2  dir3  finaldir.zip

root@CloudVedas:~/unziptest#

If you want to see other useful options on unzip you can use below command

unzip -hh

So above we have seen how you can use zip and unzip in Linux. zip is a good utility for smaller files and directories but if you need better compression you should use tar.gz. Check out our post on most useful tar command examples if you want to know more about tar.gz and tar.bz2 or other compression methods in Linux.

If you want to transfer this file out of the Linux server check our post on how to transfer files to and from linux .

Do let us know in comments section if you have any query or suggestion about this post.

Solved : Unable to locate package error in Ubuntu

Unable to locate package ubuntu

During installation of a package in ubuntu you may get an error 
Unable to locate package . 

In this post we will show you how you can fix that error and continue with your installation. 

Below is a sample error I got while installing vagrant.  But, the solution discussed below is common for any package installation in ubuntu.


root@cloudvedas:~# apt install vagrant
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package vagrant

To resolve this issue you have to update your apt repo. You can simply do this by running below command as root user or use sudo .


root@cloudvedas:~# apt update

or

user@cloudvedas:~# sudo apt update


Once the apt update is successfully completed you can try the installation once more.


root@cloudvedas:~# apt install vagrant

or

user@cloudvedas:~# sudo apt install vagrant



It should work now.

Do let us know in the comment section if you are still facing any issue after following the above steps.