chrisluiz16

git day 2 with for loop jinja

Jul 6th, 2023
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 20.80 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5. ####---------------------------------- Task 1  --------------------####
  6.  
  7.  
  8. [ec2-user@ip-172-31-32-164 ~]$ echo "linux" >linux.txt
  9. [ec2-user@ip-172-31-32-164 ~]$ echo "linux" >centos.txt
  10. [ec2-user@ip-172-31-32-164 ~]$
  11. [ec2-user@ip-172-31-32-164 ~]$ echo "windows" >windows.txt
  12. [ec2-user@ip-172-31-32-164 ~]$
  13. [ec2-user@ip-172-31-32-164 ~]$
  14.  
  15.  
  16. [ec2-user@ip-172-31-32-164 ~]$ ll
  17. total 12
  18. -rw-r--r--. 1 ec2-user ec2-user 6 Jul  6 11:46 centos.txt
  19. -rw-r--r--. 1 ec2-user ec2-user 6 Jul  6 11:46 linux.txt
  20. -rw-r--r--. 1 ec2-user ec2-user 8 Jul  6 11:46 windows.txt
  21.  
  22.  
  23.  
  24.  
  25.  
  26. #### Init command ####
  27.  
  28.  
  29. [ec2-user@ip-172-31-32-164 git-project]$ git init
  30. hint: Using 'master' as the name for the initial branch. This default branch name
  31. hint: is subject to change. To configure the initial branch name to use in all
  32. hint: of your new repositories, which will suppress this warning, call:
  33. hint:
  34. hint:  git config --global init.defaultBranch <name>
  35. hint:
  36. hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and
  37. hint: 'development'. The just-created branch can be renamed via this command:
  38. hint:
  39. hint:  git branch -m <name>
  40. Initialized empty Git repository in /home/ec2-user/git-project/.git/
  41. [ec2-user@ip-172-31-32-164 git-project]$
  42. [ec2-user@ip-172-31-32-164 git-project]$
  43. [ec2-user@ip-172-31-32-164 git-project]$ git config user.name chrisluiz16
  44. [ec2-user@ip-172-31-32-164 git-project]$
  45. [ec2-user@ip-172-31-32-164 git-project]$ git config user.email [email protected]
  46. [ec2-user@ip-172-31-32-164 git-project]$
  47.  
  48.  
  49. .git/
  50. ├── branches
  51. ├── config
  52. ├── description
  53. ├── HEAD
  54. ├── hooks
  55. │   ├── applypatch-msg.sample
  56. │   ├── commit-msg.sample
  57. │   ├── fsmonitor-watchman.sample
  58. │   ├── post-update.sample
  59. │   ├── pre-applypatch.sample
  60. │   ├── pre-commit.sample
  61. │   ├── pre-merge-commit.sample
  62. │   ├── prepare-commit-msg.sample
  63. │   ├── pre-push.sample
  64. │   ├── pre-rebase.sample
  65. │   ├── pre-receive.sample
  66. │   ├── push-to-checkout.sample
  67. │   └── update.sample
  68. ├── index
  69. ├── info
  70. │   └── exclude
  71. ├── objects
  72. │   ├── a0
  73. │   │   └── 8e1f35eb7c510c1d29584d7edc575339876a01
  74. │   ├── info
  75. │   └── pack
  76. └── refs
  77.     ├── heads
  78.     └── tags
  79.    
  80.    
  81. ### git status before commit ####
  82.    
  83.  
  84. [ec2-user@ip-172-31-32-164 git-project]$ git status
  85. On branch master
  86.  
  87. No commits yet
  88.  
  89. Changes to be committed:
  90.  (use "git rm --cached <file>..." to unstage)
  91.         new file:  centos.txt
  92.         new file:  linux.txt
  93.  
  94. Untracked files:
  95.  (use "git add <file>..." to include in what will be committed)
  96.         windows.txt
  97.        
  98.        
  99.        
  100.        
  101. #### git add and commit ####
  102.  
  103. [ec2-user@ip-172-31-32-164 git-project]$ git add windows.txt
  104. [ec2-user@ip-172-31-32-164 git-project]$
  105. [ec2-user@ip-172-31-32-164 git-project]$
  106. [ec2-user@ip-172-31-32-164 git-project]$ git status
  107. On branch master
  108.  
  109. No commits yet
  110.  
  111. Changes to be committed:
  112.  (use "git rm --cached <file>..." to unstage)
  113.         new file:  centos.txt
  114.         new file:  linux.txt
  115.         new file:  windows.txt
  116.  
  117. [ec2-user@ip-172-31-32-164 git-project]$
  118. [ec2-user@ip-172-31-32-164 git-project]$
  119. [ec2-user@ip-172-31-32-164 git-project]$
  120. [ec2-user@ip-172-31-32-164 git-project]$ git status
  121. On branch master
  122.  
  123. No commits yet
  124.  
  125. Changes to be committed:
  126.  (use "git rm --cached <file>..." to unstage)
  127.         new file:  centos.txt
  128.         new file:  linux.txt
  129.         new file:  windows.txt
  130.  
  131. [ec2-user@ip-172-31-32-164 git-project]$
  132. [ec2-user@ip-172-31-32-164 git-project]$
  133. [ec2-user@ip-172-31-32-164 git-project]$
  134. [ec2-user@ip-172-31-32-164 git-project]$
  135. [ec2-user@ip-172-31-32-164 git-project]$
  136. [ec2-user@ip-172-31-32-164 git-project]$
  137. [ec2-user@ip-172-31-32-164 git-project]$
  138. [ec2-user@ip-172-31-32-164 git-project]$ git commit -m "commit 1"
  139. [master (root-commit) 3551239] commit 1
  140.  3 files changed, 3 insertions(+)
  141.  create mode 100644 centos.txt
  142.  create mode 100644 linux.txt
  143.  create mode 100644 windows.txt
  144. [ec2-user@ip-172-31-32-164 git-project]$
  145. [ec2-user@ip-172-31-32-164 git-project]$
  146. [ec2-user@ip-172-31-32-164 git-project]$
  147. [ec2-user@ip-172-31-32-164 git-project]$ git status
  148. On branch master
  149. nothing to commit, working tree clean
  150. [ec2-user@ip-172-31-32-164 git-project]$
  151. [ec2-user@ip-172-31-32-164 git-project]$
  152. [ec2-user@ip-172-31-32-164 git-project]$ tree .git/
  153. .git/
  154. ├── branches
  155. ├── COMMIT_EDITMSG
  156. ├── config
  157. ├── description
  158. ├── HEAD
  159. ├── hooks
  160. │   ├── applypatch-msg.sample
  161. │   ├── commit-msg.sample
  162. │   ├── fsmonitor-watchman.sample
  163. │   ├── post-update.sample
  164. │   ├── pre-applypatch.sample
  165. │   ├── pre-commit.sample
  166. │   ├── pre-merge-commit.sample
  167. │   ├── prepare-commit-msg.sample
  168. │   ├── pre-push.sample
  169. │   ├── pre-rebase.sample
  170. │   ├── pre-receive.sample
  171. │   ├── push-to-checkout.sample
  172. │   └── update.sample
  173. ├── index
  174. ├── info
  175. │   └── exclude
  176. ├── logs
  177. │   ├── HEAD
  178. │   └── refs
  179. │       └── heads
  180. │           └── master
  181. ├── objects
  182. │   ├── 35
  183. │   │   └── 51239a7470412b9c39d11e3c4ebd2e18cefde8
  184. │   ├── 8e
  185. │   │   └── 1a55995ee061d80a8c62a725bc30ab9974f154
  186. │   ├── 9b
  187. │   │   └── adbe1166c48303cd0dc714600330742265dbd7
  188. │   ├── a0
  189. │   │   └── 8e1f35eb7c510c1d29584d7edc575339876a01
  190. │   ├── info
  191. │   └── pack
  192. └── refs
  193.     ├── heads
  194.     │   └── master
  195.     └── tags
  196.  
  197. 16 directories, 26 files
  198.  
  199.  
  200.  
  201. #### git log ####
  202.  
  203. [ec2-user@ip-172-31-32-164 git-project]$ git log
  204. commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8 (HEAD -> master)
  205. Author: chrisluiz16 <[email protected]>
  206. Date:  Thu Jul 6 12:00:28 2023 +0000
  207.  
  208.  
  209.  
  210.  
  211. #### git cat the first commit ####
  212.  
  213. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  214. tree 9badbe1166c48303cd0dc714600330742265dbd7
  215. author chrisluiz16 <[email protected]> 1688644828 +0000
  216. committer chrisluiz16 <[email protected]> 1688644828 +0000
  217.  
  218. commit 1
  219. [ec2-user@ip-172-31-32-164 git-project]$
  220. [ec2-user@ip-172-31-32-164 git-project]$
  221. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 9badbe1166c48303cd0dc714600330742265dbd7
  222. 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01    centos.txt
  223. 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01    linux.txt
  224. 100644 blob 8e1a55995ee061d80a8c62a725bc30ab9974f154    windows.txt
  225. [ec2-user@ip-172-31-32-164 git-project]$
  226. [ec2-user@ip-172-31-32-164 git-project]$
  227. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p a08e1f35eb7c510c1d29584d7edc575339876a01
  228. linux
  229. [ec2-user@ip-172-31-32-164 git-project]$
  230. [ec2-user@ip-172-31-32-164 git-project]$
  231.  
  232.  
  233.  
  234. #### Modifying the cenrtos.txt ####
  235.  
  236.  
  237. [ec2-user@ip-172-31-32-164 git-project]$ echo "I'm centos">>centos.txt
  238. [ec2-user@ip-172-31-32-164 git-project]$
  239. [ec2-user@ip-172-31-32-164 git-project]$
  240. [ec2-user@ip-172-31-32-164 git-project]$ cat centos.txt
  241. linux
  242. I'm centos
  243. [ec2-user@ip-172-31-32-164 git-project]$
  244. [ec2-user@ip-172-31-32-164 git-project]$
  245. [ec2-user@ip-172-31-32-164 git-project]$
  246. [ec2-user@ip-172-31-32-164 git-project]$ git status
  247. On branch master
  248. Changes not staged for commit:
  249.  (use "git add <file>..." to update what will be committed)
  250.   (use "git restore <file>..." to discard changes in working directory)
  251.         modified:  centos.txt
  252.  
  253. no changes added to commit (use "git add" and/or "git commit -a")
  254. \
  255. [ec2-user@ip-172-31-32-164 git-project]$
  256. [ec2-user@ip-172-31-32-164 git-project]$
  257. [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
  258. 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0       centos.txt
  259. 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0       linux.txt
  260. 100644 8e1a55995ee061d80a8c62a725bc30ab9974f154 0       windows.txt
  261. [ec2-user@ip-172-31-32-164 git-project]$
  262. [ec2-user@ip-172-31-32-164 git-project]$
  263. [ec2-user@ip-172-31-32-164 git-project]$ git add .
  264. [ec2-user@ip-172-31-32-164 git-project]$
  265. [ec2-user@ip-172-31-32-164 git-project]$
  266. [ec2-user@ip-172-31-32-164 git-project]$ git status
  267. On branch master
  268. Changes to be committed:
  269.  (use "git restore --staged <file>..." to unstage)
  270.         modified:  centos.txt
  271.  
  272. [ec2-user@ip-172-31-32-164 git-project]$
  273. [ec2-user@ip-172-31-32-164 git-project]$
  274. [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
  275. 100644 353851c920cae7e1a42c798b21023a35eda12efb 0       centos.txt
  276. 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0       linux.txt
  277. 100644 8e1a55995ee061d80a8c62a725bc30ab9974f154 0       windows.txt
  278. [ec2-user@ip-172-31-32-164 git-project]$
  279. [ec2-user@ip-172-31-32-164 git-project]$
  280. [ec2-user@ip-172-31-32-164 git-project]$ tree .git
  281. .git
  282. ├── branches
  283. ├── COMMIT_EDITMSG
  284. ├── config
  285. ├── description
  286. ├── HEAD
  287. ├── hooks
  288. │   ├── applypatch-msg.sample
  289. │   ├── commit-msg.sample
  290. │   ├── fsmonitor-watchman.sample
  291. │   ├── post-update.sample
  292. │   ├── pre-applypatch.sample
  293. │   ├── pre-commit.sample
  294. │   ├── pre-merge-commit.sample
  295. │   ├── prepare-commit-msg.sample
  296. │   ├── pre-push.sample
  297. │   ├── pre-rebase.sample
  298. │   ├── pre-receive.sample
  299. │   ├── push-to-checkout.sample
  300. │   └── update.sample
  301. ├── index
  302. ├── info
  303. │   └── exclude
  304. ├── logs
  305. │   ├── HEAD
  306. │   └── refs
  307. │       └── heads
  308. │           └── master
  309. ├── objects
  310. │   ├── 35
  311. │   │   ├── 3851c920cae7e1a42c798b21023a35eda12efb
  312. │   │   └── 51239a7470412b9c39d11e3c4ebd2e18cefde8
  313. │   ├── 8e
  314. │   │   └── 1a55995ee061d80a8c62a725bc30ab9974f154
  315. │   ├── 9b
  316. │   │   └── adbe1166c48303cd0dc714600330742265dbd7
  317. │   ├── a0
  318. │   │   └── 8e1f35eb7c510c1d29584d7edc575339876a01
  319. │   ├── info
  320. │   └── pack
  321. └── refs
  322.     ├── heads
  323.     │   └── master
  324.     └── tags
  325.  
  326. 16 directories, 27 files
  327.  
  328.  
  329.  
  330. #### second commit ####
  331.  
  332. [ec2-user@ip-172-31-32-164 git-project]$ git log
  333. commit b8becbbecdeda2a4a347df7adef634355946f059 (HEAD -> master)
  334. Author: chrisluiz16 <[email protected]>
  335. Date:  Thu Jul 6 12:14:57 2023 +0000
  336.  
  337.     commit 2
  338.  
  339. commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  340. Author: chrisluiz16 <[email protected]>
  341. Date:  Thu Jul 6 12:00:28 2023 +0000
  342.  
  343.     commit 1
  344. [ec2-user@ip-172-31-32-164 git-project]$
  345. [ec2-user@ip-172-31-32-164 git-project]$
  346. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p b8becbbecdeda2a4a347df7adef634355946f059
  347. tree ea927f0202980f97998319cc145b5ff34548416f
  348. parent 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  349. author chrisluiz16 <[email protected]> 1688645697 +0000
  350. committer chrisluiz16 <[email protected]> 1688645697 +0000
  351.  
  352. commit 2
  353. [ec2-user@ip-172-31-32-164 git-project]$
  354.  
  355.  
  356. #### Branch pointer  pointing to the latest commit ####
  357.  
  358.  
  359. [ec2-user@ip-172-31-32-164 git-project]$ git log
  360. commit b8becbbecdeda2a4a347df7adef634355946f059 (HEAD -> master)
  361. Author: chrisluiz16 <[email protected]>
  362. Date:  Thu Jul 6 12:14:57 2023 +0000
  363.  
  364.     commit 2
  365.  
  366. commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  367. Author: chrisluiz16 <[email protected]>
  368. Date:  Thu Jul 6 12:00:28 2023 +0000
  369.  
  370.     commit 1
  371. [ec2-user@ip-172-31-32-164 git-project]$
  372. [ec2-user@ip-172-31-32-164 git-project]$
  373. [ec2-user@ip-172-31-32-164 git-project]$ cat .git/refs/heads/master
  374. b8becbbecdeda2a4a347df7adef634355946f059
  375.  
  376.  
  377. #### head pointer ####
  378.  
  379. ec2-user@ip-172-31-32-164 git-project]$ cat .git/HEAD
  380. ref: refs/heads/master
  381.  
  382.  
  383. #### git inspecting the commit or indexfile backup ####
  384.  
  385. [ec2-user@ip-172-31-32-164 git-project]$ git log
  386. commit b8becbbecdeda2a4a347df7adef634355946f059 (HEAD -> master)
  387. Author: chrisluiz16 <[email protected]>
  388. Date:  Thu Jul 6 12:14:57 2023 +0000
  389.  
  390.     commit 2
  391.  
  392. commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  393. Author: chrisluiz16 <[email protected]>
  394. Date:  Thu Jul 6 12:00:28 2023 +0000
  395.  
  396.     commit 1
  397.  
  398.  
  399. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p b8becbbecdeda2a4a347df7adef634355946f059
  400. tree ea927f0202980f97998319cc145b5ff34548416f
  401. parent 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  402. author chrisluiz16 <[email protected]> 1688645697 +0000
  403. committer chrisluiz16 <[email protected]> 1688645697 +0000
  404.  
  405. commit 2
  406. [ec2-user@ip-172-31-32-164 git-project]$
  407. [ec2-user@ip-172-31-32-164 git-project]$
  408. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  409. tree 9badbe1166c48303cd0dc714600330742265dbd7
  410. author chrisluiz16 <[email protected]> 1688644828 +0000
  411. committer chrisluiz16 <[email protected]> 1688644828 +0000
  412.  
  413. commit 1
  414. [ec2-user@ip-172-31-32-164 git-project]$
  415. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 9badbe1166c48303cd0dc714600330742265dbd7
  416. 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01    centos.txt
  417. 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01    linux.txt
  418. 100644 blob 8e1a55995ee061d80a8c62a725bc30ab9974f154    windows.txt
  419.  
  420.  
  421.  
  422. #### third commit ####
  423.  
  424.  
  425. [ec2-user@ip-172-31-32-164 git-project]$ echo "I'm using windows OS">>windows.txt
  426. [ec2-user@ip-172-31-32-164 git-project]$
  427. [ec2-user@ip-172-31-32-164 git-project]$
  428. [ec2-user@ip-172-31-32-164 git-project]$ git status
  429. On branch master
  430. Changes not staged for commit:
  431.  (use "git add <file>..." to update what will be committed)
  432.   (use "git restore <file>..." to discard changes in working directory)
  433.         modified:  windows.txt
  434.  
  435. no changes added to commit (use "git add" and/or "git commit -a")
  436. [ec2-user@ip-172-31-32-164 git-project]$
  437. [ec2-user@ip-172-31-32-164 git-project]$
  438. [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
  439. 100644 353851c920cae7e1a42c798b21023a35eda12efb 0       centos.txt
  440. 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0       linux.txt
  441. 100644 8e1a55995ee061d80a8c62a725bc30ab9974f154 0       windows.txt
  442. [ec2-user@ip-172-31-32-164 git-project]$
  443. [ec2-user@ip-172-31-32-164 git-project]$
  444. [ec2-user@ip-172-31-32-164 git-project]$ git add .
  445. [ec2-user@ip-172-31-32-164 git-project]$
  446. [ec2-user@ip-172-31-32-164 git-project]$ git ls-files -s
  447. 100644 353851c920cae7e1a42c798b21023a35eda12efb 0       centos.txt
  448. 100644 a08e1f35eb7c510c1d29584d7edc575339876a01 0       linux.txt
  449. 100644 d5555955f14bc34476b1e08de0511f03e83ea6ee 0       windows.txt
  450. [ec2-user@ip-172-31-32-164 git-project]$
  451. [ec2-user@ip-172-31-32-164 git-project]$
  452. [ec2-user@ip-172-31-32-164 git-project]$ git commit -m "commit 3"
  453. [master 7293f20] commit 3
  454.  1 file changed, 1 insertion(+)
  455. [ec2-user@ip-172-31-32-164 git-project]$
  456. [ec2-user@ip-172-31-32-164 git-project]$
  457. [ec2-user@ip-172-31-32-164 git-project]$
  458. [ec2-user@ip-172-31-32-164 git-project]$ git log
  459. commit 7293f205ad7610f454d80c8a0355c4ac8fe80bcf (HEAD -> master)
  460. Author: chrisluiz16 <[email protected]>
  461. Date:  Thu Jul 6 12:24:24 2023 +0000
  462.  
  463.     commit 3
  464.  
  465. commit b8becbbecdeda2a4a347df7adef634355946f059
  466. Author: chrisluiz16 <[email protected]>
  467. Date:  Thu Jul 6 12:14:57 2023 +0000
  468.  
  469.     commit 2
  470.  
  471. commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  472. Author: chrisluiz16 <[email protected]>
  473. Date:  Thu Jul 6 12:00:28 2023 +0000
  474.  
  475.     commit 1
  476.    
  477. #### Checking the 2nd commit values ###
  478.  
  479. [ec2-user@ip-172-31-32-164 git-project]$ git log
  480. commit 7293f205ad7610f454d80c8a0355c4ac8fe80bcf (HEAD -> master)
  481. Author: chrisluiz16 <[email protected]>
  482. Date:  Thu Jul 6 12:24:24 2023 +0000
  483.  
  484.     commit 3
  485.  
  486. commit b8becbbecdeda2a4a347df7adef634355946f059
  487. Author: chrisluiz16 <[email protected]>
  488. Date:  Thu Jul 6 12:14:57 2023 +0000
  489.  
  490.     commit 2
  491.  
  492. commit 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  493. Author: chrisluiz16 <[email protected]>
  494. Date:  Thu Jul 6 12:00:28 2023 +0000
  495.  
  496.     commit 1
  497.    
  498. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p 7293f205ad7610f454d80c8a0355c4ac8fe80bcf
  499. tree 159d7b57f20e2771ca74c53f165a68928dc5b576
  500. parent b8becbbecdeda2a4a347df7adef634355946f059
  501. author chrisluiz16 <[email protected]> 1688646264 +0000
  502. committer chrisluiz16 <[email protected]> 1688646264 +0000
  503.  
  504. commit 3
  505. [ec2-user@ip-172-31-32-164 git-project]$
  506. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p b8becbbecdeda2a4a347df7adef634355946f059
  507. tree ea927f0202980f97998319cc145b5ff34548416f
  508. parent 3551239a7470412b9c39d11e3c4ebd2e18cefde8
  509. author chrisluiz16 <[email protected]> 1688645697 +0000
  510. committer chrisluiz16 <[email protected]> 1688645697 +0000
  511.  
  512. commit 2
  513. [ec2-user@ip-172-31-32-164 git-project]$
  514. [ec2-user@ip-172-31-32-164 git-project]$
  515. [ec2-user@ip-172-31-32-164 git-project]$ git cat-file -p ea927f0202980f97998319cc145b5ff34548416f
  516. 100644 blob 353851c920cae7e1a42c798b21023a35eda12efb    centos.txt
  517. 100644 blob a08e1f35eb7c510c1d29584d7edc575339876a01    linux.txt
  518. 100644 blob 8e1a55995ee061d80a8c62a725bc30ab9974f154    windows.txt
  519. [ec2-user@ip-172-31-32-164 git-project]$
  520.  
  521.  
  522.  
  523. #### ------------------------------------- Task 2 using variable as jinja 2 template   --------------------------------- ####
  524.  
  525.  
  526.  
  527. [ec2-user@ip-172-31-32-164 ~]$ cat nginx.conf.tmpl
  528. http {
  529.    upstream backend {
  530.       server {{ server1 }};
  531.       server {{ server2 }};
  532.       server {{ server3 }};
  533.    }
  534.    server {
  535.       listen 80;
  536.  
  537.       location / {
  538.           proxy_pass http://backend;
  539.       }
  540.    }
  541. }
  542.  
  543.  
  544.  
  545.  
  546. ### Playbook ####
  547.  
  548. [ec2-user@ip-172-31-32-164 ~]$ cat main.yml
  549. ---
  550.  
  551. - name: "Nginx conf for loop"
  552.   hosts: amazon
  553.   vars:
  554.     server1: "192.168.0.1"
  555.     server2: "192.168.0.2"
  556.     server3: "192.168.0.3"
  557.   tasks:
  558.     - name: "Checking the working of jinja2 template"
  559.       template:
  560.         src: ./nginx.conf.tmpl
  561.         dest: /tmp/nginx.conf
  562.        
  563.        
  564.  
  565.  
  566. #### Output ####
  567.  
  568. [ec2-user@ip-172-31-32-164 ~]$ ansible-playbook -i inventory main.yml
  569.  
  570. PLAY [Nginx conf for loop] *********************************************************************************************
  571.  
  572. TASK [Gathering Facts] *************************************************************************************************
  573. ok: [172.31.10.148]
  574.  
  575. TASK [Checking the working of jinja2 template] *************************************************************************
  576. changed: [172.31.10.148]
  577.  
  578. PLAY RECAP *************************************************************************************************************
  579. 172.31.10.148              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
  580.  
  581.  
  582. #### Verification ####
  583.  
  584. [ec2-user@ip-172-31-10-148 ~]$ cat /tmp/nginx.conf
  585. http {
  586.    upstream backend {
  587.       server 192.168.0.1;
  588.       server 192.168.0.2;
  589.       server 192.168.0.3;
  590.    }
  591.    server {
  592.       listen 80;
  593.  
  594.       location / {
  595.           proxy_pass http://backend;
  596.       }
  597.    }
  598. }
  599.  
  600.  
  601.  
  602.  
  603. ##### For loop playbook ####
  604.  
  605.  
  606. [ec2-user@ip-172-31-32-164 ~]$ cat main.yml
  607. ---
  608.  
  609. - name: "Nginx conf for loop"
  610.   hosts: amazon
  611.   vars:
  612.     servers:
  613.      - 192.168.0.1
  614.       - 192.168.0.2
  615.       - 192.168.0.3
  616.       - 172.32.0.1
  617.       - 10.0.0.1
  618.       - 172.32.17.254
  619.   tasks:
  620.     - name: "Checking the working of jinja2 template"
  621.       template:
  622.         src: ./nginx.conf.tmpl
  623.         dest: /tmp/nginx.conf
  624.        
  625.        
  626. #### nginx.conf.tmpl ####
  627.  
  628. [ec2-user@ip-172-31-32-164 ~]$ cat nginx.conf.tmpl
  629. http {
  630.    upstream backend {
  631.     {% for ip_addr in servers %}
  632.       server {{ ip_addr }};
  633.     {% endfor %}
  634.    }
  635.    server {
  636.       listen 80;
  637.  
  638.       location / {
  639.           proxy_pass http://backend;
  640.       }
  641.    }
  642. }
  643.  
  644.  
  645. ### Output ###
  646.  
  647. [ec2-user@ip-172-31-32-164 ~]$ ansible-playbook -i inventory main.yml
  648.  
  649. PLAY [Nginx conf for loop] *********************************************************************************************
  650.  
  651. TASK [Gathering Facts] *************************************************************************************************
  652. ok: [172.31.10.148]
  653.  
  654. TASK [Checking the working of jinja2 template] *************************************************************************
  655. changed: [172.31.10.148]
  656.  
  657. PLAY RECAP *************************************************************************************************************
  658. 172.31.10.148              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
  659.  
  660.  
  661. #### Verification ###
  662.  
  663. [ec2-user@ip-172-31-10-148 ~]$  cat /tmp/nginx.conf
  664. http {
  665.    upstream backend {
  666.           server 192.168.0.1;
  667.           server 192.168.0.2;
  668.           server 192.168.0.3;
  669.           server 172.32.0.1;
  670.           server 10.0.0.1;
  671.           server 172.32.17.254;
  672.        }
  673.    server {
  674.       listen 80;
  675.  
  676.       location / {
  677.           proxy_pass http://backend;
  678.       }
  679.    }
  680. }
Advertisement
Add Comment
Please, Sign In to add comment