Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ####---------------------------------- Task 1 --------------------####
- [ec2-user@ip-172-31-32-164 ~]$ echo "linux" >linux.txt
- [ec2-user@ip-172-31-32-164 ~]$ echo "linux" >centos.txt
- [ec2-user@ip-172-31-32-164 ~]$
- [ec2-user@ip-172-31-32-164 ~]$ echo "windows" >windows.txt
- [ec2-user@ip-172-31-32-164 ~]$
- [ec2-user@ip-172-31-32-164 ~]$
- [ec2-user@ip-172-31-32-164 ~]$ ll
- total 12
- -rw-r--r--. 1 ec2-user ec2-user 6 Jul 6 11:46 centos.txt
- -rw-r--r--. 1 ec2-user ec2-user 6 Jul 6 11:46 linux.txt
- -rw-r--r--. 1 ec2-user ec2-user 8 Jul 6 11:46 windows.txt
- #### Init command ####
- [ec2-user@ip-172-31-32-164 git-project]$ git init
- hint: Using 'master' as the name for the initial branch. This default branch name
- hint: is subject to change. To configure the initial branch name to use in all
- hint: of your new repositories, which will suppress this warning, call:
- hint:
- hint: git config --global init.defaultBranch <name>
- hint:
- hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
- hint: 'development'. The just-created branch can be renamed via this command:
- hint:
- hint: git branch -m <name>
- Initialized empty Git repository in /home/ec2-user/git-project/.git/
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git config user.name chrisluiz16
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- .git/
- ├── branches
- ├── config
- ├── description
- ├── HEAD
- ├── hooks
- │ ├── applypatch-msg.sample
- │ ├── commit-msg.sample
- │ ├── fsmonitor-watchman.sample
- │ ├── post-update.sample
- │ ├── pre-applypatch.sample
- │ ├── pre-commit.sample
- │ ├── pre-merge-commit.sample
- │ ├── prepare-commit-msg.sample
- │ ├── pre-push.sample
- │ ├── pre-rebase.sample
- │ ├── pre-receive.sample
- │ ├── push-to-checkout.sample
- │ └── update.sample
- ├── index
- ├── info
- │ └── exclude
- ├── objects
- │ ├── a0
- │ │ └── 8e1f35eb7c510c1d29584d7edc575339876a01
- │ ├── info
- │ └── pack
- └── refs
- ├── heads
- └── tags
- ### git status before commit ####
- [ec2-user@ip-172-31-32-164 git-project]$ git status
- On branch master
- No commits yet
- Changes to be committed:
- (use "git rm --cached <file>..." to unstage)
- new file: centos.txt
- new file: linux.txt
- Untracked files:
- (use "git add <file>..." to include in what will be committed)
- windows.txt
- #### git add and commit ####
- [ec2-user@ip-172-31-32-164 git-project]$ git add windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git status
- On branch master
- No commits yet
- Changes to be committed:
- (use "git rm --cached <file>..." to unstage)
- new file: centos.txt
- new file: linux.txt
- new file: windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git status
- On branch master
- No commits yet
- Changes to be committed:
- (use "git rm --cached <file>..." to unstage)
- new file: centos.txt
- new file: linux.txt
- new file: windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git commit -m "commit 1"
- [master (root-commit) 3551239] commit 1
- 3 files changed, 3 insertions(+)
- create mode 100644 centos.txt
- create mode 100644 linux.txt
- create mode 100644 windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git status
- On branch master
- nothing to commit, working tree clean
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ tree .git/
- .git/
- ├── branches
- ├── COMMIT_EDITMSG
- ├── config
- ├── description
- ├── HEAD
- ├── hooks
- │ ├── applypatch-msg.sample
- │ ├── commit-msg.sample
- │ ├── fsmonitor-watchman.sample
- │ ├── post-update.sample
- │ ├── pre-applypatch.sample
- │ ├── pre-commit.sample
- │ ├── pre-merge-commit.sample
- │ ├── prepare-commit-msg.sample
- │ ├── pre-push.sample
- │ ├── pre-rebase.sample
- │ ├── pre-receive.sample
- │ ├── push-to-checkout.sample
- │ └── update.sample
- ├── index
- ├── info
- │ └── exclude
- ├── logs
- │ ├── HEAD
- │ └── refs
- │ └── heads
- │ └── master
- ├── objects
- │ ├── 35
- │ │ └── 51239a7470412b9c39d11e3c4ebd2e18cefde8
- │ ├── 8e
- │ │ └── 1a55995ee061d80a8c62a725bc30ab9974f154
- │ ├── 9b
- │ │ └── adbe1166c48303cd0dc714600330742265dbd7
- │ ├── a0
- │ │ └── 8e1f35eb7c510c1d29584d7edc575339876a01
- │ ├── info
- │ └── pack
- └── refs
- ├── heads
- │ └── master
- └── tags
- 16 directories, 26 files
- #### git log ####
- [ec2-user@ip-172-31-32-164 git-project]$ git log
- commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8 (HEAD -> master)
- Date: Thu Jul 6 12:00:28 2023 +0000
- #### git cat the first commit ####
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- tree 9badbe1166c48303cd0dc714600330742265dbd7
- author chrisluiz16 <[email protected]> 1688644828 +0000
- committer chrisluiz16 <[email protected]> 1688644828 +0000
- commit 1
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 9badbe1166c48303cd0dc714600330742265dbd7
- 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01 centos.txt
- 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01 linux.txt
- 100644 blob 8e1a55995ee061d80a8c62a725bc30ab9974f154 windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p a08e1f35eb7c510c1d29584d7edc575339876a01
- linux
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- #### Modifying the cenrtos.txt ####
- [ec2-user@ip-172-31-32-164 git-project]$ echo "I'm centos">>centos.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ cat centos.txt
- linux
- I'm centos
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git status
- On branch master
- Changes not staged for commit:
- (use "git add <file>..." to update what will be committed)
- (use "git restore <file>..." to discard changes in working directory)
- modified: centos.txt
- no changes added to commit (use "git add" and/or "git commit -a")
- \
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
- 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0 centos.txt
- 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0 linux.txt
- 100644 8e1a55995ee061d80a8c62a725bc30ab9974f154 0 windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git add .
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git status
- On branch master
- Changes to be committed:
- (use "git restore --staged <file>..." to unstage)
- modified: centos.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
- 100644 353851c920cae7e1a42c798b21023a35eda12efb 0 centos.txt
- 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0 linux.txt
- 100644 8e1a55995ee061d80a8c62a725bc30ab9974f154 0 windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ tree .git
- .git
- ├── branches
- ├── COMMIT_EDITMSG
- ├── config
- ├── description
- ├── HEAD
- ├── hooks
- │ ├── applypatch-msg.sample
- │ ├── commit-msg.sample
- │ ├── fsmonitor-watchman.sample
- │ ├── post-update.sample
- │ ├── pre-applypatch.sample
- │ ├── pre-commit.sample
- │ ├── pre-merge-commit.sample
- │ ├── prepare-commit-msg.sample
- │ ├── pre-push.sample
- │ ├── pre-rebase.sample
- │ ├── pre-receive.sample
- │ ├── push-to-checkout.sample
- │ └── update.sample
- ├── index
- ├── info
- │ └── exclude
- ├── logs
- │ ├── HEAD
- │ └── refs
- │ └── heads
- │ └── master
- ├── objects
- │ ├── 35
- │ │ ├── 3851c920cae7e1a42c798b21023a35eda12efb
- │ │ └── 51239a7470412b9c39d11e3c4ebd2e18cefde8
- │ ├── 8e
- │ │ └── 1a55995ee061d80a8c62a725bc30ab9974f154
- │ ├── 9b
- │ │ └── adbe1166c48303cd0dc714600330742265dbd7
- │ ├── a0
- │ │ └── 8e1f35eb7c510c1d29584d7edc575339876a01
- │ ├── info
- │ └── pack
- └── refs
- ├── heads
- │ └── master
- └── tags
- 16 directories, 27 files
- #### second commit ####
- [ec2-user@ip-172-31-32-164 git-project]$ git log
- commit b8becbbecdeda2a4a347df7adef634355946f059 (HEAD -> master)
- Date: Thu Jul 6 12:14:57 2023 +0000
- commit 2
- commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- Date: Thu Jul 6 12:00:28 2023 +0000
- commit 1
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p b8becbbecdeda2a4a347df7adef634355946f059
- tree ea927f0202980f97998319cc145b5ff34548416f
- parent 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- author chrisluiz16 <[email protected]> 1688645697 +0000
- committer chrisluiz16 <[email protected]> 1688645697 +0000
- commit 2
- [ec2-user@ip-172-31-32-164 git-project]$
- #### Branch pointer pointing to the latest commit ####
- [ec2-user@ip-172-31-32-164 git-project]$ git log
- commit b8becbbecdeda2a4a347df7adef634355946f059 (HEAD -> master)
- Date: Thu Jul 6 12:14:57 2023 +0000
- commit 2
- commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- Date: Thu Jul 6 12:00:28 2023 +0000
- commit 1
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ cat .git/refs/heads/master
- b8becbbecdeda2a4a347df7adef634355946f059
- #### head pointer ####
- ec2-user@ip-172-31-32-164 git-project]$ cat .git/HEAD
- ref: refs/heads/master
- #### git inspecting the commit or indexfile backup ####
- [ec2-user@ip-172-31-32-164 git-project]$ git log
- commit b8becbbecdeda2a4a347df7adef634355946f059 (HEAD -> master)
- Date: Thu Jul 6 12:14:57 2023 +0000
- commit 2
- commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- Date: Thu Jul 6 12:00:28 2023 +0000
- commit 1
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p b8becbbecdeda2a4a347df7adef634355946f059
- tree ea927f0202980f97998319cc145b5ff34548416f
- parent 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- author chrisluiz16 <[email protected]> 1688645697 +0000
- committer chrisluiz16 <[email protected]> 1688645697 +0000
- commit 2
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- tree 9badbe1166c48303cd0dc714600330742265dbd7
- author chrisluiz16 <[email protected]> 1688644828 +0000
- committer chrisluiz16 <[email protected]> 1688644828 +0000
- commit 1
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 9badbe1166c48303cd0dc714600330742265dbd7
- 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01 centos.txt
- 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01 linux.txt
- 100644 blob 8e1a55995ee061d80a8c62a725bc30ab9974f154 windows.txt
- #### third commit ####
- [ec2-user@ip-172-31-32-164 git-project]$ echo "I'm using windows OS">>windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git status
- On branch master
- Changes not staged for commit:
- (use "git add <file>..." to update what will be committed)
- (use "git restore <file>..." to discard changes in working directory)
- modified: windows.txt
- no changes added to commit (use "git add" and/or "git commit -a")
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
- 100644 353851c920cae7e1a42c798b21023a35eda12efb 0 centos.txt
- 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0 linux.txt
- 100644 8e1a55995ee061d80a8c62a725bc30ab9974f154 0 windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git add .
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
- 100644 353851c920cae7e1a42c798b21023a35eda12efb 0 centos.txt
- 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0 linux.txt
- 100644 d5555955f14bc34476b1e08de0511f03e83ea6ee 0 windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git commit -m "commit 3"
- [master 7293f20] commit 3
- 1 file changed, 1 insertion(+)
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git log
- commit 7293f205ad7610f454d80c8a0355c4ac8fe80bcf (HEAD -> master)
- Date: Thu Jul 6 12:24:24 2023 +0000
- commit 3
- commit b8becbbecdeda2a4a347df7adef634355946f059
- Date: Thu Jul 6 12:14:57 2023 +0000
- commit 2
- commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- Date: Thu Jul 6 12:00:28 2023 +0000
- commit 1
- #### Checking the 2nd commit values ###
- [ec2-user@ip-172-31-32-164 git-project]$ git log
- commit 7293f205ad7610f454d80c8a0355c4ac8fe80bcf (HEAD -> master)
- Date: Thu Jul 6 12:24:24 2023 +0000
- commit 3
- commit b8becbbecdeda2a4a347df7adef634355946f059
- Date: Thu Jul 6 12:14:57 2023 +0000
- commit 2
- commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- Date: Thu Jul 6 12:00:28 2023 +0000
- commit 1
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 7293f205ad7610f454d80c8a0355c4ac8fe80bcf
- tree 159d7b57f20e2771ca74c53f165a68928dc5b576
- parent b8becbbecdeda2a4a347df7adef634355946f059
- author chrisluiz16 <[email protected]> 1688646264 +0000
- committer chrisluiz16 <[email protected]> 1688646264 +0000
- commit 3
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p b8becbbecdeda2a4a347df7adef634355946f059
- tree ea927f0202980f97998319cc145b5ff34548416f
- parent 3551239a7470412b9c39d11e3c4ebd2e18cefde8
- author chrisluiz16 <[email protected]> 1688645697 +0000
- committer chrisluiz16 <[email protected]> 1688645697 +0000
- commit 2
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$
- [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p ea927f0202980f97998319cc145b5ff34548416f
- 100644 blob 353851c920cae7e1a42c798b21023a35eda12efb centos.txt
- 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01 linux.txt
- 100644 blob 8e1a55995ee061d80a8c62a725bc30ab9974f154 windows.txt
- [ec2-user@ip-172-31-32-164 git-project]$
- #### ------------------------------------- Task 2 using variable as jinja 2 template --------------------------------- ####
- [ec2-user@ip-172-31-32-164 ~]$ cat nginx.conf.tmpl
- http {
- upstream backend {
- server {{ server1 }};
- server {{ server2 }};
- server {{ server3 }};
- }
- server {
- listen 80;
- location / {
- proxy_pass http://backend;
- }
- }
- }
- ### Playbook ####
- [ec2-user@ip-172-31-32-164 ~]$ cat main.yml
- ---
- - name: "Nginx conf for loop"
- hosts: amazon
- vars:
- server1: "192.168.0.1"
- server2: "192.168.0.2"
- server3: "192.168.0.3"
- tasks:
- - name: "Checking the working of jinja2 template"
- template:
- src: ./nginx.conf.tmpl
- dest: /tmp/nginx.conf
- #### Output ####
- [ec2-user@ip-172-31-32-164 ~]$ ansible-playbook -i inventory main.yml
- PLAY [Nginx conf for loop] *********************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************
- ok: [172.31.10.148]
- TASK [Checking the working of jinja2 template] *************************************************************************
- changed: [172.31.10.148]
- PLAY RECAP *************************************************************************************************************
- 172.31.10.148 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- #### Verification ####
- [ec2-user@ip-172-31-10-148 ~]$ cat /tmp/nginx.conf
- http {
- upstream backend {
- server 192.168.0.1;
- server 192.168.0.2;
- server 192.168.0.3;
- }
- server {
- listen 80;
- location / {
- proxy_pass http://backend;
- }
- }
- }
- ##### For loop playbook ####
- [ec2-user@ip-172-31-32-164 ~]$ cat main.yml
- ---
- - name: "Nginx conf for loop"
- hosts: amazon
- vars:
- servers:
- - 192.168.0.1
- - 192.168.0.2
- - 192.168.0.3
- - 172.32.0.1
- - 10.0.0.1
- - 172.32.17.254
- tasks:
- - name: "Checking the working of jinja2 template"
- template:
- src: ./nginx.conf.tmpl
- dest: /tmp/nginx.conf
- #### nginx.conf.tmpl ####
- [ec2-user@ip-172-31-32-164 ~]$ cat nginx.conf.tmpl
- http {
- upstream backend {
- {% for ip_addr in servers %}
- server {{ ip_addr }};
- {% endfor %}
- }
- server {
- listen 80;
- location / {
- proxy_pass http://backend;
- }
- }
- }
- ### Output ###
- [ec2-user@ip-172-31-32-164 ~]$ ansible-playbook -i inventory main.yml
- PLAY [Nginx conf for loop] *********************************************************************************************
- TASK [Gathering Facts] *************************************************************************************************
- ok: [172.31.10.148]
- TASK [Checking the working of jinja2 template] *************************************************************************
- changed: [172.31.10.148]
- PLAY RECAP *************************************************************************************************************
- 172.31.10.148 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- #### Verification ###
- [ec2-user@ip-172-31-10-148 ~]$ cat /tmp/nginx.conf
- http {
- upstream backend {
- server 192.168.0.1;
- server 192.168.0.2;
- server 192.168.0.3;
- server 172.32.0.1;
- server 10.0.0.1;
- server 172.32.17.254;
- }
- server {
- listen 80;
- location / {
- proxy_pass http://backend;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment