Advertisement
sreehariskumar

ansible

Feb 11th, 2023
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.24 KB | None | 0 0
  1. ANSIBLE
  2. =======
  3. (on master)
  4.  
  5. $ sudo amazon-linux-extras install ansible2 -y
  6.  
  7. $ ansible --version
  8. ansible 2.9.23
  9. config file = /etc/ansible/ansible.cfg
  10. configured module search path = [u'/home/ec2-user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  11. ansible python module location = /usr/lib/python2.7/site-packages/ansible
  12. executable location = /usr/bin/ansible
  13. python version = 2.7.18 (default, May 25 2022, 14:30:51) [GCC 7.3.1 20180712 (Red Hat 7.3.1-15)]
  14.  
  15. $ cat inventory
  16. [amazon]
  17. 172.31.14.237 ansible_user="ec2-user" ansible_port=22 ansible_ssh_private_key_file="aws.pem"
  18.  
  19. $ ansible -i inventory amazon -m ping
  20. The authenticity of host '172.31.14.237 (172.31.14.237)' can't be established.
  21. ECDSA key fingerprint is SHA256:VE2/2D9i0H3vi84ly3Vp1qW7C5VEZbQ3d38Z41e9IcQ.
  22. ECDSA key fingerprint is MD5:9c:37:9f:28:a4:08:c7:99:ea:ff:66:fe:72:c2:15:21.
  23. Are you sure you want to continue connecting (yes/no)? yes
  24. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  25. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  26. information.
  27. 172.31.14.237 | SUCCESS => {
  28. "ansible_facts": {
  29. "discovered_interpreter_python": "/usr/bin/python"
  30. },
  31. "changed": false,
  32. "ping": "pong"
  33. }
  34.  
  35.  
  36. $ ansible -i inventory amazon -m yum -a "name=httpd state=present"
  37. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  38. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  39. information.
  40. 172.31.14.237 | FAILED! => {
  41. "ansible_facts": {
  42. "discovered_interpreter_python": "/usr/bin/python"
  43. },
  44. "changed": false,
  45. "changes": {
  46. "installed": [
  47. "httpd"
  48. ]
  49. },
  50. "msg": "You need to be root to perform this command.\n",
  51. "rc": 1,
  52. "results": [
  53. "Loaded plugins: extras_suggestions, langpacks, priorities, update-motd\n"
  54. ]
  55. }
  56.  
  57.  
  58.  
  59. $ ansible -i inventory amazon -b -m yum -a "name=httpd state=present"
  60. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  61. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  62. information.
  63. 172.31.14.237 | CHANGED => {
  64. "ansible_facts": {
  65. "discovered_interpreter_python": "/usr/bin/python"
  66. },
  67. "changed": true,
  68.  
  69.  
  70.  
  71. $ ansible -i inventory amazon -b -m yum -a "name=httpd state=present"
  72. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  73. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  74. information.
  75. 172.31.14.237 | SUCCESS => {
  76. "ansible_facts": {
  77. "discovered_interpreter_python": "/usr/bin/python"
  78. },
  79. "changed": false,
  80.  
  81.  
  82.  
  83. $ ansible -i inventory amazon -b -m yum -a "name=httpd,php state=present"
  84. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  85. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  86. information.
  87. 172.31.14.237 | CHANGED => {
  88. "ansible_facts": {
  89. "discovered_interpreter_python": "/usr/bin/python"
  90. },
  91. "changed": true,
  92. "changes": {
  93. "installed": [
  94. "PHP"
  95.  
  96.  
  97.  
  98. $ ansible -i inventory amazon -b -m yum -a "name=httpd,php,mariadb-server state=present"
  99. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  100. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  101. information.
  102. 172.31.14.237 | CHANGED => {
  103. "ansible_facts": {
  104. "discovered_interpreter_python": "/usr/bin/python"
  105. },
  106. "changed": true,
  107. "changes": {
  108. "installed": [
  109. "mariadb-server"
  110.  
  111.  
  112.  
  113. $ ansible -i inventory -b amazon -m service -a "name=httpd state=started"
  114. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  115. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  116. information.
  117. 172.31.14.237 | CHANGED => {
  118. "ansible_facts": {
  119. "discovered_interpreter_python": "/usr/bin/python"
  120. },
  121. "changed": true,
  122. "name": "httpd",
  123. "state": "started",
  124.  
  125.  
  126.  
  127. $ ansible -i inventory -b amazon -m service -a "name=mariadb state=started"
  128. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  129. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  130. information.
  131. 172.31.14.237 | CHANGED => {
  132. "ansible_facts": {
  133. "discovered_interpreter_python": "/usr/bin/python"
  134. },
  135. "changed": true,
  136. "name": "mariadb",
  137. "state": "started",
  138.  
  139.  
  140.  
  141. $ ansible -i inventory -b amazon -m service -a "name=httpd state=started"
  142. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  143. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  144. information.
  145. 172.31.14.237 | SUCCESS => {
  146. "ansible_facts": {
  147. "discovered_interpreter_python": "/usr/bin/python"
  148. },
  149. "changed": false,
  150. "name": "httpd",
  151. "state": "started",
  152.  
  153.  
  154.  
  155. $ ansible -i inventory -b amazon -m service -a "name=mariadb state=stopped"
  156. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  157. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  158. information.
  159. 172.31.14.237 | CHANGED => {
  160. "ansible_facts": {
  161. "discovered_interpreter_python": "/usr/bin/python"
  162. },
  163. "changed": true,
  164. "name": "mariadb",
  165. "state": "stopped",
  166.  
  167.  
  168.  
  169. $ wget https://www.tooplate.com/zip-templates/2128_tween_agency.zip ; unzip 2128_tween_agency.zip ; mv 2128_tween_agency website ; rm -rf *.zip
  170.  
  171. $ ansible -i inventory -b amazon -m copy -a "src=./website/ dest=/var/www/html/"
  172. 172.31.14.237 | CHANGED => {
  173. "changed": true,
  174. "dest": "/var/www/html/",
  175. "src": "/home/ec2-user/./website/"
  176. }
  177.  
  178.  
  179. $ ansible -i inventory -b amazon -m copy -a "src=./website/ dest=/var/www/html/"
  180. 172.31.14.237 | SUCCESS => {
  181. "changed": false,
  182. "dest": "/var/www/html/",
  183. "src": "/home/ec2-user/./website/"
  184. }
  185.  
  186.  
  187. $ ansible -i inventory -b amazon -m copy -a "src=./website/ dest=/var/www/html/"
  188. 172.31.14.237 | CHANGED => {
  189. "changed": true,
  190. "dest": "/var/www/html/",
  191. "src": "/home/ec2-user/./website/"
  192. }
  193.  
  194.  
  195. $ cat simple-site-hosting-playbook.yml
  196. ---
  197.  
  198. - name: "site hosting"
  199. hosts: amazon
  200. become: true
  201. tasks:
  202.  
  203. - name: "installing httpd"
  204. yum:
  205. name: httpd
  206. state: present
  207.  
  208. - name: "starting httpd service"
  209. service:
  210. name: httpd
  211. state: started
  212. enabled: true
  213.  
  214. - name: "copying site contents"
  215. copy:
  216. src: "./website/"
  217. dest: "/var/www/html/"
  218. owner: apache
  219. group: apache
  220.  
  221.  
  222.  
  223.  
  224. $ ansible-playbook -i inventory simple-site-hosting-playbook.yml --syntax-check
  225.  
  226. playbook: simple-site-hosting-playbook.yml
  227.  
  228.  
  229.  
  230. $ ansible-playbook -i inventory simple-site-hosting-playbook.yml
  231.  
  232. PLAY [site hosting] ****************************************************************************************************************************
  233.  
  234. TASK [Gathering Facts] *************************************************************************************************************************
  235. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  236. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  237. information.
  238. ok: [172.31.14.237]
  239.  
  240. TASK [installing httpd] ************************************************************************************************************************
  241. ok: [172.31.14.237]
  242.  
  243. TASK [starting httpd service] ******************************************************************************************************************
  244. changed: [172.31.14.237]
  245.  
  246. TASK [copying site contents] *******************************************************************************************************************
  247. changed: [172.31.14.237]
  248.  
  249. PLAY RECAP *************************************************************************************************************************************
  250. 172.31.14.237 : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  251.  
  252.  
  253.  
  254.  
  255. $ ansible -i inventory -b amazon -m yum -a "name=* state=latest"
  256. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  257. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  258. information.
  259. 172.31.14.237 | CHANGED => {
  260. "ansible_facts": {
  261. "discovered_interpreter_python": "/usr/bin/python"
  262. },
  263. "changed": true,
  264.  
  265.  
  266.  
  267. $ cat sreehari.txt
  268. content1
  269.  
  270.  
  271.  
  272. $ ansible -i inventory amazon -m copy -a "src=sreehari.txt dest=/tmp/"
  273. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  274. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  275. information.
  276. 172.31.14.237 | CHANGED => {
  277. "ansible_facts": {
  278. "discovered_interpreter_python": "/usr/bin/python"
  279. },
  280. "changed": true,
  281. "checksum": "b29930dda02406077d96a7b7a08ce282b3de6961",
  282. "dest": "/tmp/sreehari.txt",
  283.  
  284.  
  285.  
  286. $ ansible -i inventory amazon -m file -a "path=/tmp/sreehari.txt state=absent"
  287. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  288. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  289. information.
  290. 172.31.14.237 | CHANGED => {
  291. "ansible_facts": {
  292. "discovered_interpreter_python": "/usr/bin/python"
  293. },
  294. "changed": true,
  295. "path": "/tmp/sreehari.txt",
  296. "state": "absent"
  297. }
  298.  
  299.  
  300.  
  301.  
  302. $ ansible -i inventory amazon -m copy -a "src=sreehari.txt dest=/tmp/"
  303. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  304. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  305. information.
  306. 172.31.14.237 | CHANGED => {
  307. "ansible_facts": {
  308. "discovered_interpreter_python": "/usr/bin/python"
  309. },
  310. "changed": true,
  311. "checksum": "b29930dda02406077d96a7b7a08ce282b3de6961",
  312. "dest": "/tmp/sreehari.txt",
  313.  
  314.  
  315.  
  316.  
  317. $ ansible -i inventory amazon -m copy -a "src=sreehari.txt dest=/tmp/linux.txt"
  318. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  319. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  320. information.
  321. 172.31.14.237 | CHANGED => {
  322. "ansible_facts": {
  323. "discovered_interpreter_python": "/usr/bin/python"
  324. },
  325. "changed": true,
  326. "checksum": "b29930dda02406077d96a7b7a08ce282b3de6961",
  327. "dest": "/tmp/linux.txt",
  328.  
  329.  
  330.  
  331.  
  332. $ ansible -i inventory amazon -m file -a "src=/tmp/linux.txt dest=/tmp/sreehari.txt state=link"
  333. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  334. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  335. information.
  336. 172.31.14.237 | CHANGED => {
  337. "ansible_facts": {
  338. "discovered_interpreter_python": "/usr/bin/python"
  339. },
  340. "changed": true,
  341. "dest": "/tmp/sreehari.txt",
  342. "gid": 1000,
  343. "group": "ec2-user",
  344. "mode": "0777",
  345. "owner": "ec2-user",
  346. "size": 14,
  347. "src": "/tmp/linux.txt",
  348. "state": "link",
  349. "uid": 1000
  350.  
  351.  
  352.  
  353.  
  354.  
  355. $ ansible -i inventory -b amazon -m user -a "name=user state=present"
  356. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  357. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  358. information.
  359. 172.31.14.237 | CHANGED => {
  360. "ansible_facts": {
  361. "discovered_interpreter_python": "/usr/bin/python"
  362. },
  363. "changed": true,
  364.  
  365.  
  366.  
  367.  
  368. $ ansible -i inventory -b amazon -m user -a "name=user state=absent"
  369. [WARNING]: Platform linux on host 172.31.14.237 is using the discovered Python interpreter at /usr/bin/python, but future installation of
  370. another Python interpreter could change this. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more
  371. information.
  372. 172.31.14.237 | CHANGED => {
  373. "ansible_facts": {
  374. "discovered_interpreter_python": "/usr/bin/python"
  375. },
  376. "changed": true,
  377. "force": false,
  378. "name": "user",
  379. "remove": false,
  380. "state": "absent"
  381. }
  382.  
  383.  
  384.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement