DevOps Cheat

GIT CHEAT SHEET.
============

Upload data in GIT
# mkdir git-upload ; cd git-upload/
# git init
# git remote add origin https://github.com/vdarole/kvm.git
# git add .
# git status
# git commit -m 'Update on 12Jan2023'
# git push origin master

# git logs

# git reset "commit id"

It will ask for user name(vallabh_darole@yahoo.co.in ) and password
to get password login to git portal --> Setting --> Developer settings --> Personal access tokens --> Tokens --> Generate new token
Download data from GIT:
# git clone https://github.com/vdarole/kvm.git

This is a sequence of commands executed in the terminal to initialize a Git repository and push a new branch to GitHub:

Initializes a new Git repository in the current directory.
# git init

 Stages all files in the current directory for the next commit.
# git add .

Commits the staged changes with a message.
# git commit -m "April 2023 Commit"

if the don't work try the below steps 
----------------------------------------------------
# git commit --allow-empty -m "Initial commit"
# git branch
# git branch -M main
----------------------------------------------------

Adds a remote repository on GitHub with the name "origin".
# git remote add origin https://github.com/vdarole/puppet.git

Sets the global user name and email for Git.
# git config --global user.name vallabh
# git config --global user.email vallabh_darole@yahoo.co.in

 Lists all local branches.
# git branch

Creates a new branch called "april".
# git branch april

Lists all local branches again.
# git branch

Switches to the "april" branch.
# git checkout april 

Lists all local branches again.
# git branch

Shows the status of the repository, including any changes and untracked files.
# git status

Pushes the "april" branch to the "origin" remote repository on GitHub.
# git push origin april

ANSIBLE

========
Important terms used in Ansible
Ansible server: The machine where Ansible is installed and from which all tasks and playbooks will be ran
Module: Basically, a module is a command or set of similar Ansible commands meant to be executed on the client-side
Task: A task is a section that consists of a single procedure to be completed
Role: A way of organizing tasks and related files to be later called in a playbook
Fact: Information fetched from the client system from the global variables with the gather-facts operation
Inventory: File containing data about the ansible client servers. Defined in later examples as hosts file
Play: Execution of a playbook
Handler: Task which is called only if a notifier is present
Notifier: Section attributed to a task which calls a handler if the output is changed
Tag: Name set to a task which can be used later on to issue just that specific task or group of tasks.
Playbooks: Lists of tasks that automatically execute against hosts
Ad-hoc Commands: Uses the /usr/bin/ansible command-line tool to automate a single task on one or more managed nodes. ad hoc commands are quick and easy, but they are not reusable

Host file
$ cat /etc/ansible/hosts
[kvm-base]
kvm01
.
$ cat /etc/ansible/hosts
kvm01 ansible_connection=ssh anssible_user=root ansible_ssh_pass=redhat
win01 ansible_connection=winrm ansible_user=administrator ansible_password=Azure#12345678
[kvm] ### GROUPS NAME ##
kvm01

$ ansible --list-hosts kvm ## get host name details.
$ ansible -m setup pup01 ## get host system details.

To see the documents
# ansible-doc -s ping

Below module are used by System Admin
ping, shell , copy , file, yum, service, parted, archive, firewalld, cron, user

ADHOC Command.
$ ansible all -a uptime
# ansible centos -a uptime --ask-pass
# cat /etc/ansible/ansible.cfg | grep host_key_checking
host_key_checking = False
# ansible centos -a whoami -i /home/ansible/inventory.txt --ask-pass
$ ansible all -a 'dmidecode' -b | grep -A5 "System Information"
## sudo requred(-b).
$ ansible all -a " systemctl restart rsyslog" -b ## sudo requred(-b).
$ ansible all -a uptime -o
## To get in table format(-o)
$ ansible all -m shell -a "mkdir /etc/backup-yum-repos.d" -b ## Shell
$ ansible all -a 'dmidecode' -b | grep -A5 "System Information" ##Command
$ ansible centos -m file -a "dest=/home/vdarole/data/b mode=600 owner=root group=root" -b ## File
$ ansible all -m yum -a 'name=net-tools state=installed' -b ## Yum
$ ansible all -m service -a "name=ntpd state=started" -b ## Service
$ ansible redhat -m cron -a "hour=17 minute=15 job=/home/vdarole/date.sh "
## Cron
$ ansible all -m user -a "name=admin " -b ## User

PLAYBOOK FOR PING THE SERVERS.
$ cat ping-test.yml
---
- name: first playbook ping test.
hosts: all
tasks:
- name: ping test
ping:
$ ansible-playbook --syntax-check ping-test.yml  ## To check the syntax
$ ansible-playbook -C ping-test.yml ## Dry Check
$ ansible-playbook ping-test.yml --step

 

No comments:

Post a Comment