The Automation Code
48 FOLLOWERS
Hi, This is Chirag Nagrekar, author and writer of this blog. I have more than 9 years of experience in managing and implementing IT Infrastructure and primarily working and focusing on Infrastructure Automation Projects. This blog is for System Admins and novice automation developers to help them for Automation and Simplification of processes and make their life easier. This blog primarily..
The Automation Code
1M ago
a. Concat String with ‘+’ Operator
In Python concatenating strings are easy. For example, let’s say you have two strings to merge then you put the plus (‘+’) operator to merge two strings.
str1 = "Hello"
str2 = "World"
str = str1 + ' ' + str2
print(str)
The output will be “Hello World“. If you have more strings then just add more operators to merge the strings.
b. Concat string with Join function
Another way to merge the string is by using the Join() function of the string. For example,
str1 = "Hello"
str2 = "Python"
str3 = "World"
str = ' '.join([str1,str2,str3])
print(str)
The output ..read more
The Automation Code
2M ago
create a dictionary in Python
A dictionary in Python is a key-value pair of objects. Key-value pairs can be different data types. To create an empty dictionary, below is the syntax.
dict_example = {}
Let’s create a dictionary with some data.
car_models = { "Creta": 2024,
"Venue" : 2023,
"Nexon":2022
}
Print this dictionary.
Let’s check the datatype of the dictionary.
print("\nCheck Datatype")
print(type(car_models))
Data type ‘dict’ as you see refers to the class dictionary.
To print the specific value.
print(f"Creta Model : {car_models['Creta']}")
print(f"Venue Model : {car ..read more
The Automation Code
3M ago
Error: response from daemon: Bad response from Docker engine
When you run docker commands you may have encountered the error “ERROR: Error response from daemon: Bad response from Docker engine” sometimes on Windows and Linux OS when running the docker desktop.
For example,
Workaround
Check if the docker desktop is running. If the docker desktop is running, check if the docker desktop service is running.
for Windows OS, you can check the docker-desktop service using,
Get-Service "Docker Desktop Service"
To start the docker desktop service on the windows run the below command.
Start-Serv ..read more
The Automation Code
3M ago
You can set environment variables in Azure Pipeline so they can be used in the scripts and application code. This variable is process level means it is available during that pipeline run only.
To set environment variables in Azure Pipeline, the env variable is used in the steps subtasks. Below are the steps subtasks.
steps: [ task | script | powershell | pwsh | bash | checkout | download | downloadBuild | getPackage | publish | template | reviewApp ]
Let’s take some examples to understand the same.
Using the env variable at the task level
trigger:
- none
pool:
vmImage: windows-latest
jo ..read more
The Automation Code
3M ago
There are two types of arrays in PowerShell.
Fixed array
Dynamic Array
Fixed Array
Fixed arrays are the ones whose values cannot be removed or added. Their sizes are fixed. For example, below is the fixed-size array.
$array1 = @("Cat","Dog","Cow")
If you try to add/remove elements, it will fail.
$array1.add("Tiger")
Some programs you write may need the array dynamically allocated so the elements can be added or removed when needed.
ArrayList
This dynamic array is called the arraylist in PowerShell. There are two ways to create dynamic arrays (ArrayList).
$array2 =New-Object -TypeNam ..read more
The Automation Code
3M ago
In the previous articles, we mentioned setting up environment variables using PowerShell and Python in Windows OS. In this article, we will set up environment variables with GoLang.
Set up environment variables with GoLang. a. Process Level
Setting up environment variables at the process level is easy with GoLang. Below is an example of that.
package main
import (
"fmt"
"os"
)
func main(){
env_key := "azSub"
env_value := "TestSub1"
err := os.Setenv(env_key,env_value)
if err != nil {
fmt.Println("Error Setting up process level ..read more
The Automation Code
3M ago
In the previous article, we have seen how to set the environment variables with GUI, PowerShell, and CMD. In this section, let’s continue to set the environment variable programmatically using Python
Set Environment Variable using Python a. Process Level
Setting up environment variables at the process level is easy with Python. We need to import the OS module and use the environment function to set the value.
For Example,
import os
os.environ["azSub"] = "TestSub1"
print(os.environ["azSub"])
Setting up environment variables at the machine or user levels isn’t straightforward in Python like ..read more
The Automation Code
3M ago
What is an environment variable in Windows?
In Windows, an environment variable is a map/hash kind of variable with a Key-Value pair that stores the values of the variable inside the operating system so that the applications or processes can use it.
There are three types of environment variables.
Machine Level (Permanent)
User Level (Permanent)
Process Level (Temporary)
Process level has the highest preference while the User level is the second and third is the machine level. So if the same variable is set across the three levels with different values then the Process level will be given th ..read more
The Automation Code
4M ago
Why do we need an Azure DevOps (ADO) extension in Azure CLI?
Well, you know how to manage Azure DevOps services (Pipeline, workItems, Repo, Artifacts, etc) from the portal. If you are a DevOps engineer or Automation guy then you would love to manage the ADO services with the command line (Azure CLI).
Managing ADO services with the command line is very easy and makes your work faster like managing pipelines, work items, artifacts, etc.
Pre-Requisites:
Azure CLI Tool installed (must be above 2.10.1).
Azure DevOps Account
Once you have Azure CLI installed, you are eligible to install the exten ..read more
The Automation Code
4M ago
Why terraform module is required?
If you are new to terraform, I will advise you to first check the terraform basics.
Alright, you might have worked with multiple programming languages where you want to reuse your code and you write functions.
Similarly in Terraform, we create modules so that the same resource block can be called and used multiple times by just passing values.
For example, consider this scenario where you have to create a storage account for two environments (QA and Prod). In a typical environment what you have done without a module is create two resources and pass variables s ..read more