chrisluiz16

Untitled

Jun 20th, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.07 KB | None | 0 0
  1.  
  2.  
  3. -------------------------------------------------------------- Task 1-------------------------------------------
  4.  
  5.  
  6. ec2-user@ip-172-31-5-142 ~]$ cat inventory
  7. [amazon]
  8. 172.31.5.5 ansible_port=22 ansible_ssh_user="ec2-user" ansible_ssh_private_key_file="aws.pem"
  9. 172.31.7.82 ansible_port=22 ansible_ssh_user="ec2-user" ansible_ssh_private_key_file="aws.pem"
  10.  
  11.  
  12.  
  13. [ec2-user@ip-172-31-5-142 ~]$ ansible -i inventory amazon -f 1 -m ping
  14. The authenticity of host '172.31.5.5 (172.31.5.5)' can't be established.
  15. ED25519 key fingerprint is SHA256:X6J9GdLG8a2dDY3/KBJpqaXtm0Bxy9aRYF4mNABwvnc.
  16. This key is not known by any other names
  17. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
  18. 172.31.5.5 | SUCCESS => {
  19. "ansible_facts": {
  20. "discovered_interpreter_python": "/usr/bin/python3.9"
  21. },
  22. "changed": false,
  23. "ping": "pong"
  24. }
  25. The authenticity of host '172.31.7.82 (172.31.7.82)' can't be established.
  26. ED25519 key fingerprint is SHA256:lsR/+H4FcaYos/3+msnbGnznOo7/23ZYNnrV2Umx2lA.
  27. This key is not known by any other names
  28. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
  29. 172.31.7.82 | SUCCESS => {
  30. "ansible_facts": {
  31. "discovered_interpreter_python": "/usr/bin/python3.9"
  32. },
  33. "changed": false,
  34. "ping": "pong"
  35. }
  36.  
  37.  
  38.  
  39. [ec2-user@ip-172-31-5-142 ~]$ git clone https://github.com/Chris-luiz-16/aws-elb-site.git website/
  40. Cloning into 'website'...
  41. remote: Enumerating objects: 248, done.
  42. remote: Counting objects: 100% (13/13), done.
  43. remote: Compressing objects: 100% (13/13), done.
  44. remote: Total 248 (delta 2), reused 5 (delta 0), pack-reused 235
  45. Receiving objects: 100% (248/248), 1.45 MiB | 9.19 MiB/s, done.
  46.  
  47.  
  48.  
  49.  
  50.  
  51. [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
  52. ---
  53. - name: "LAMP installation for php website"
  54. hosts: amazon
  55. become: true
  56. vars:
  57. httpd_owner: apache
  58. httpd_group: apache
  59. packages:
  60. - httpd
  61. - php
  62. - mariadb105-server
  63. tasks:
  64. - name: "LAMP packages installation"
  65. yum:
  66. name: "{{ packages }}"
  67. state: present
  68. - name: "httpd service enable"
  69. service:
  70. name: httpd
  71. state: started
  72. enabled: true
  73. - name: "php service enable"
  74. service:
  75. name: php-fpm
  76. state: started
  77. enabled: true
  78. - name: "mariadb service enable"
  79. service:
  80. name: mariadb
  81. state: started
  82. enabled: true
  83. - name: "Copying website to the document root"
  84. copy:
  85. src: ./website/
  86. dest: /var/www/html/
  87. owner: "{{ httpd_owner }}"
  88. group: "{{ httpd_group }}"
  89.  
  90.  
  91.  
  92.  
  93.  
  94. [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
  95.  
  96. PLAY [LAMP installation for php website] *******************************************************************************
  97.  
  98. TASK [Gathering Facts] *************************************************************************************************
  99. [WARNING]: Platform linux on host 172.31.7.82 is using the discovered Python interpreter at /usr/bin/python3.9, but
  100. future installation of another Python interpreter could change the meaning of that path. See
  101. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  102. ok: [172.31.7.82]
  103. [WARNING]: Platform linux on host 172.31.5.5 is using the discovered Python interpreter at /usr/bin/python3.9, but
  104. future installation of another Python interpreter could change the meaning of that path. See
  105. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  106. ok: [172.31.5.5]
  107.  
  108. TASK [LAMP packages installation] **************************************************************************************
  109. changed: [172.31.7.82]
  110. changed: [172.31.5.5]
  111.  
  112. TASK [httpd service enable] ********************************************************************************************
  113. changed: [172.31.7.82]
  114. changed: [172.31.5.5]
  115.  
  116. TASK [php service enable] **********************************************************************************************
  117. changed: [172.31.7.82]
  118. changed: [172.31.5.5]
  119.  
  120. TASK [mariadb service enable] ******************************************************************************************
  121. changed: [172.31.5.5]
  122. changed: [172.31.7.82]
  123.  
  124. TASK [Copying website to the document root] ****************************************************************************
  125. changed: [172.31.5.5]
  126. changed: [172.31.7.82]
  127.  
  128. PLAY RECAP *************************************************************************************************************
  129. 172.31.5.5 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  130. 172.31.7.82 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. -------------------------------------------------------------- Task 2 [variables declaration] -------------------------------------------
  139.  
  140.  
  141. [ec2-user@ip-172-31-5-142 ~]$ cat packages.yml && echo
  142. ---
  143. packages:
  144. - httpd
  145. - php
  146. - mariadb105-server
  147.  
  148. [ec2-user@ip-172-31-5-142 ~]$
  149. [ec2-user@ip-172-31-5-142 ~]$
  150. [ec2-user@ip-172-31-5-142 ~]$ cat apache-group.yml && echo
  151. ---
  152. httpd_owner: apache
  153. httpd_group: apache
  154.  
  155.  
  156. [ec2-user@ip-172-31-5-142 ~]$
  157. [ec2-user@ip-172-31-5-142 ~]$
  158. [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
  159. ---
  160. - name: "LAMP installation for php website"
  161. hosts: amazon
  162. become: true
  163. vars_files:
  164. - packages.yml
  165. - apache-group.yml
  166. tasks:
  167. - name: "LAMP packages installation"
  168. yum:
  169. name: "{{ packages }}"
  170. state: present
  171. - name: "httpd service enable"
  172. service:
  173. name: httpd
  174. state: restarted
  175. enabled: true
  176. - name: "php service enable"
  177. service:
  178. name: php-fpm
  179. state: restarted
  180. enabled: true
  181. - name: "mariadb service enable"
  182. service:
  183. name: mariadb
  184. state: restarted
  185. enabled: true
  186. - name: "Copying website to the document root"
  187. copy:
  188. src: ./website/
  189. dest: /var/www/html/
  190. owner: "{{ httpd_owner }}"
  191. group: "{{ httpd_group }}"
  192.  
  193.  
  194.  
  195.  
  196. [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
  197.  
  198. PLAY [LAMP installation for php website] *******************************************************************************
  199.  
  200. TASK [Gathering Facts] *************************************************************************************************
  201. [WARNING]: Platform linux on host 172.31.7.82 is using the discovered Python interpreter at /usr/bin/python3.9, but
  202. future installation of another Python interpreter could change the meaning of that path. See
  203. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  204. ok: [172.31.7.82]
  205. [WARNING]: Platform linux on host 172.31.5.5 is using the discovered Python interpreter at /usr/bin/python3.9, but
  206. future installation of another Python interpreter could change the meaning of that path. See
  207. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  208. ok: [172.31.5.5]
  209.  
  210. TASK [LAMP packages installation] **************************************************************************************
  211. ok: [172.31.7.82]
  212. ok: [172.31.5.5]
  213.  
  214. TASK [httpd service enable] ********************************************************************************************
  215. changed: [172.31.7.82]
  216. changed: [172.31.5.5]
  217.  
  218. TASK [php service enable] **********************************************************************************************
  219. changed: [172.31.7.82]
  220. changed: [172.31.5.5]
  221.  
  222. TASK [mariadb service enable] ******************************************************************************************
  223. changed: [172.31.5.5]
  224. changed: [172.31.7.82]
  225.  
  226. TASK [Copying website to the document root] ****************************************************************************
  227. ok: [172.31.5.5]
  228. ok: [172.31.7.82]
  229.  
  230. PLAY RECAP *************************************************************************************************************
  231. 172.31.5.5 : ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  232. 172.31.7.82 : ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  233.  
  234.  
  235.  
  236.  
  237.  
  238. -------------------------------------------------------------- Task 3 [with_items] -------------------------------------------
  239.  
  240.  
  241. [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
  242. ---
  243. - name: "LAMP installation for php website"
  244. hosts: amazon
  245. become: true
  246. vars_files:
  247. - packages.yml
  248. - apache-group.yml
  249. tasks:
  250. - name: "LAMP packages installation"
  251. yum:
  252. name: "{{ packages }}"
  253. state: present
  254. - name: "httpd,php,mariadb services enable"
  255. service:
  256. name: "{{ item }}"
  257. state: restarted
  258. enabled: true
  259. with_items:
  260. - httpd
  261. - php-fpm
  262. - mariadb
  263. - name: "Copying website to the document root"
  264. copy:
  265. src: ./website/
  266. dest: /var/www/html/
  267. owner: "{{ httpd_owner }}"
  268. group: "{{ httpd_group }}"
  269.  
  270.  
  271.  
  272.  
  273.  
  274. [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
  275.  
  276. PLAY [LAMP installation for php website] *******************************************************************************
  277.  
  278. TASK [Gathering Facts] *************************************************************************************************
  279. [WARNING]: Platform linux on host 172.31.7.82 is using the discovered Python interpreter at /usr/bin/python3.9, but
  280. future installation of another Python interpreter could change the meaning of that path. See
  281. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  282. ok: [172.31.7.82]
  283. [WARNING]: Platform linux on host 172.31.5.5 is using the discovered Python interpreter at /usr/bin/python3.9, but
  284. future installation of another Python interpreter could change the meaning of that path. See
  285. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  286. ok: [172.31.5.5]
  287.  
  288. TASK [LAMP packages installation] **************************************************************************************
  289. ok: [172.31.7.82]
  290. ok: [172.31.5.5]
  291.  
  292. TASK [httpd,php,mariadb services enable] *******************************************************************************
  293. changed: [172.31.7.82] => (item=httpd)
  294. changed: [172.31.5.5] => (item=httpd)
  295. changed: [172.31.7.82] => (item=php-fpm)
  296. changed: [172.31.5.5] => (item=php-fpm)
  297. changed: [172.31.7.82] => (item=mariadb)
  298. changed: [172.31.5.5] => (item=mariadb)
  299.  
  300. TASK [Copying website to the document root] ****************************************************************************
  301. ok: [172.31.7.82]
  302. ok: [172.31.5.5]
  303.  
  304. PLAY RECAP *************************************************************************************************************
  305. 172.31.5.5 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  306. 172.31.7.82 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315.  
  316. -------------------------------- Task 4 [variable declaration for with_items in service module] ---------------------------------------
  317.  
  318.  
  319.  
  320.  
  321. #### Declaring directly via vars
  322.  
  323. ---
  324. - name: "LAMP installation for php website"
  325. hosts: amazon
  326. become: true
  327. vars_files:
  328. - packages.yml
  329. - apache-group.yml
  330. vars:
  331. services:
  332. - httpd
  333. - php-fpm
  334. - mariadb
  335. tasks:
  336. - name: "LAMP packages installation"
  337. yum:
  338. name: "{{ packages }}"
  339. state: present
  340. - name: "httpd,php,mariadb services enable"
  341. service:
  342. name: "{{ item }}"
  343. state: restarted
  344. enabled: true
  345. with_items: "{{ services }}"
  346.  
  347. - name: "Copying website to the document root"
  348. copy:
  349. src: ./website/
  350. dest: /var/www/html/
  351. owner: "{{ httpd_owner }}"
  352. group: "{{ httpd_group }}"
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359. #### Declaring through vars_files
  360.  
  361. [ec2-user@ip-172-31-5-142 ~]$ cat service.yml && echo
  362. ---
  363. services:
  364. - httpd
  365. - php-fpm
  366. - mariadb
  367.  
  368. [ec2-user@ip-172-31-5-142 ~]$
  369. [ec2-user@ip-172-31-5-142 ~]$
  370. [ec2-user@ip-172-31-5-142 ~]$
  371. [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
  372. ---
  373. - name: "LAMP installation for php website"
  374. hosts: amazon
  375. become: true
  376. vars_files:
  377. - packages.yml
  378. - apache-group.yml
  379. - service.yml
  380. tasks:
  381. - name: "LAMP packages installation"
  382. yum:
  383. name: "{{ packages }}"
  384. state: present
  385. - name: "httpd,php,mariadb services enable"
  386. service:
  387. name: "{{ item }}"
  388. state: restarted
  389. enabled: true
  390. with_items: "{{ services }}"
  391.  
  392. - name: "Copying website to the document root"
  393. copy:
  394. src: ./website/
  395. dest: /var/www/html/
  396. owner: "{{ httpd_owner }}"
  397. group: "{{ httpd_group }}"
  398.  
  399.  
  400.  
  401. [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
  402.  
  403. PLAY [LAMP installation for php website] *******************************************************************************
  404.  
  405. TASK [Gathering Facts] *************************************************************************************************
  406. [WARNING]: Platform linux on host 172.31.5.5 is using the discovered Python interpreter at /usr/bin/python3.9, but
  407. future installation of another Python interpreter could change the meaning of that path. See
  408. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  409. ok: [172.31.5.5]
  410. [WARNING]: Platform linux on host 172.31.7.82 is using the discovered Python interpreter at /usr/bin/python3.9, but
  411. future installation of another Python interpreter could change the meaning of that path. See
  412. https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information.
  413. ok: [172.31.7.82]
  414.  
  415. TASK [LAMP packages installation] **************************************************************************************
  416. ok: [172.31.5.5]
  417. ok: [172.31.7.82]
  418.  
  419. TASK [httpd,php,mariadb services enable] *******************************************************************************
  420. changed: [172.31.7.82] => (item=httpd)
  421. changed: [172.31.5.5] => (item=httpd)
  422. changed: [172.31.7.82] => (item=php-fpm)
  423. changed: [172.31.5.5] => (item=php-fpm)
  424. changed: [172.31.7.82] => (item=mariadb)
  425. changed: [172.31.5.5] => (item=mariadb)
  426.  
  427. TASK [Copying website to the document root] ****************************************************************************
  428. ok: [172.31.7.82]
  429. ok: [172.31.5.5]
  430.  
  431. PLAY RECAP *************************************************************************************************************
  432. 172.31.5.5 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  433. 172.31.7.82 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  434.  
Advertisement
Add Comment
Please, Sign In to add comment