Git basics for day to day work

Welcome to Git basics!
This is a very basic touch up on everyday git usage.
Git is a Distributed Version Control System (DVCS), created by Linus Torvalds, primarily to address collaboration issues.

I. CLONE COMMANDS: git clone

  1. Clone a repository into a new directory

    1
    $ git clone <URL>
  2. Clone a repository into a new custom directory myApp

    1
    $ git clone <URL> myApp
  3. Clone a specific branch develop

    1
    $ git clone -b develop <URL>
  4. Create a shallow clone with a history truncated to the specified number of commits

    1
    $ git clone <URL> --depth=2
  5. Create a shallow clone with a history after the specified time.

    1
    $ git clone <URL> --shallow-since=yyyy-mm-dd
  6. Clone by providing credentials in-line

    1
    $ git clone <protocol>://<username>:password@<domain>/repo-name.git --shallow-since=yyyy-mm-dd

In the above example,

  • protocol can be : https, git, ssh, ftp
  • username and password are the credentials that has access to clone this repository.
  • domain is the git host. Ex. github or bitbucket or gitlab, etc.




II. CHECKOUT COMMANDS: git checkouy

Checking for modifications done in local

1
$ git status

Adding your locally changed files for staging

To add a specific file:

1
$ git add <file-path>

To add all the files at once:

1
2
3
$ git add --all
# OR
$ git add .

Committing the changes to local repository

1
$ git commit -m 'my commit message'

Pushing the changes to remote

1
2
3
$ git push
# OR
$ git push origin master

Pulling the latest changes from remote

1
$ git pull

Ansible & Ansible Tower (AWX) Lab Setup (PowerShell)

Magic scripts to setup Ansible & Ansible Tower (AWX) Learner’s Lab environment on a personal computer.

GOAL : Automate Setup of AWX learner’s lab setup.

Tool Stack

  • Git ( with SSH + Linux Utilities)
  • VirtualBox ( for spinning up virtual instances)
  • Vagrant ( for provisioning virtual instances using boxes )
  • Docker ( for running containers needed by AWX )

Approach

The series of steps involved in the script are illustrated in the below flow chart.

Get Started

To get started with the setup, download the below steps.

AnsibleMagicLab_Pre_Reboot.ps1

AnsibleMagicLab_Post_Reboot.ps1

Launch Sequence

Open Command Prompt in ‘Administrator’ mode.
Go to the scripts download location and execute the below command.

[1] Pre-Reboot Setup

powershell.exe -ExecutionPolicy Bypass -File AnsibleMagicLab_Pre_Reboot.ps1
On Successful installation of Vagrant, the machine should reboot.

Once the machine is up, Open Command Prompt in ‘Administrator’ mode, go to the scripts download location and execute the below command.

[1] Post-Reboot Setup

powershell.exe -ExecutionPolicy Bypass -File AnsibleMagicLab_Post_Reboot.ps1

Done that ?
Now you’ll be able to access your Ansible Tower (AWX) web interface using the Ip of the Vagrant machine.

Open up a browser and provide the IP <IP of AWX Instance> and hit Enter. You’ll get to see a page like below.

AWX Web Interface Login Screen

CREDENTIALS for AWX Login

username : admin
password : password

On successful login, you’ll see a dashboard similar to the below one.

AWX Web Interface Fresh Dashboard

PowerShell : Enable WinRm on Windows

Step 01

Download the PowerShell script provided by Ansible here: ConfigureRemotingForAnsible.ps1

Note: To execute the script, Administrator access is required.

Step 02

Now, go to the script download location and open the Command Prompt as an ‘Administrator’ and run the following command:

1
powershell.exe -ExecutionPolicy Bypass -File ConfigureRemotingForAnsible.ps1 -CertValidityDays 100

Note: Ensure that port 5986 is open in firewall rules.

That’s all you need, to enable WinRm on windows!

Enable / Disable TCP Ports

To enable / disable port accessibility on a machine, we can use the firewall-cmd utility.

Note: You need Administrator / sudo access to play around with this utility.

Switch to Root Account.

1
$ sudo su

To Install firewalld

If you already have firewall daemon available on your machine, you can skip this.

Execute the below command to install firewall daemon

1
yum install -y firewalld

To check status of firewall daemon

1
firewall-cmd --state

You should see running as the result for the above command.

Enable TCP Ports

To enable any tcp port say 9090 for example, the command you need to execute is :

1
2
firewall-cmd --zone=public --permanent --add-port=9090/tcp
firewall-cmd --reload

Enable TCP Ports

To disable any tcp port say 8090 for example, the command you need to execute is :

1
2
firewall-cmd --zone=public --permanent --remove-port=8090/tcp
firewall-cmd --reload

List open ports

To list publicly accessible ports on the machine, use the below command.

1
2
$ firewall-cmd --zone=public --list-ports
9090/tcp