Advertisement
sreehariskumar

ansible_handlers

Feb 20th, 2023
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.17 KB | None | 0 0
  1. ANSIBLE-HANDLERS
  2. ================
  3.  
  4.  
  5. $ cat site.yml
  6. ---
  7.  
  8. - name: "simple site hosting"
  9. become: yes
  10. hosts: amazon
  11. vars:
  12. httpd_owner: apache
  13. httpd_group: apache
  14. httpd_port: 80
  15. httpd_domain: mysite.1by2.online
  16. tasks:
  17.  
  18. - name: "install httpd"
  19. yum:
  20. name: httpd
  21. state: present
  22.  
  23. - name: "creating conf file from template file"
  24. template:
  25. src: "./httpd.conf.j2"
  26. dest: "/etc/httpd/conf/httpd.conf"
  27. owner: "{{ httpd_owner }}"
  28. group: "{{ httpd_group }}"
  29.  
  30. - name: "creating virtualhost from template file"
  31. template:
  32. src: "./virtualhost.conf.j2"
  33. dest: "/etc/httpd/conf.d/{{ httpd_domain }}.conf"
  34. owner: "{{ httpd_owner }}"
  35. group: "{{ httpd_group }}"
  36.  
  37. - name: "creating document root"
  38. file:
  39. path: "/var/www/html/{{ httpd_domain }}"
  40. state: directory
  41. owner: "{{ httpd_owner }}"
  42. group: "{{ httpd_group }}"
  43.  
  44. - name: "create index file"
  45. copy:
  46. content: "<h1><center>{{ ansible_fqdn }} </h1></center>"
  47. dest: "/var/www/html/{{ httpd_domain }}/index.html"
  48. owner: "{{ httpd_owner }}"
  49. group: "{{ httpd_group }}"
  50.  
  51. - name: "restarting service"
  52. service:
  53. name: httpd
  54. state: restarted
  55. enabled: true
  56.  
  57.  
  58.  
  59. $ ansible-playbook -i hosts site.yml
  60.  
  61. PLAY [simple site hosting] *********************************************************************************************************************
  62.  
  63. TASK [Gathering Facts] ***********************************************************************************************************************
  64. ok: [172.31.41.110]
  65.  
  66. TASK [install httpd] ***********************************************************************************************************************
  67. changed: [172.31.41.110]
  68.  
  69. TASK [creating conf file from template file] ***************************************************************************************************
  70. changed: [172.31.41.110]
  71.  
  72. TASK [creating virtualhost from template file] *************************************************************************************************
  73. changed: [172.31.41.110]
  74.  
  75. TASK [creating document root] ******************************************************************************************************************
  76. changed: [172.31.41.110]
  77.  
  78. TASK [create index file] ***********************************************************************************************************************
  79. changed: [172.31.41.110]
  80.  
  81. TASK [restarting service] **********************************************************************************************************************
  82. changed: [172.31.41.110]
  83.  
  84. PLAY RECAP ***********************************************************************************************************************
  85. 172.31.41.110 : ok=7 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  86.  
  87.  
  88. $ ansible -i hosts all -b -m shell -a "yum remove httpd -y ; rm -rf /etc/httpd/* /var/www/html/*"
  89.  
  90.  
  91. =======================================================================================================================
  92. $ cat site.yml
  93. ---
  94.  
  95. - name: "simple site hosting"
  96. become: yes
  97. hosts: amazon
  98. vars:
  99. httpd_owner: apache
  100. httpd_group: apache
  101. httpd_port: 80
  102. httpd_domain: mysite.1by2.online
  103. tasks:
  104.  
  105. - name: "install httpd"
  106. yum:
  107. name: httpd
  108. state: present
  109.  
  110. - name: "creating conf file from template file"
  111. template:
  112. src: "./httpd.conf.j2"
  113. dest: "/etc/httpd/conf/httpd.conf"
  114. owner: "{{ httpd_owner }}"
  115. group: "{{ httpd_group }}"
  116.  
  117. - name: "creating virtualhost from template file"
  118. template:
  119. src: "./virtualhost.conf.j2"
  120. dest: "/etc/httpd/conf.d/{{ httpd_domain }}.conf"
  121. owner: "{{ httpd_owner }}"
  122. group: "{{ httpd_group }}"
  123.  
  124. - name: "creating document root"
  125. file:
  126. path: "/var/www/html/{{ httpd_domain }}"
  127. state: directory
  128. owner: "{{ httpd_owner }}"
  129. group: "{{ httpd_group }}"
  130.  
  131. - name: "create index file"
  132. copy:
  133. content: "<h1><center>{{ ansible_fqdn }} </h1></center>"
  134. dest: "/var/www/html/{{ httpd_domain }}/index.html"
  135. owner: "{{ httpd_owner }}"
  136. group: "{{ httpd_group }}"
  137.  
  138. handlers:
  139. - name: "restarting service"
  140. service:
  141. name: httpd
  142. state: restarted
  143. enabled: true
  144.  
  145.  
  146. $ ansible-playbook -i hosts site.yml
  147.  
  148. PLAY [simple site hosting] *********************************************************************************************************************
  149.  
  150. TASK [Gathering Facts] ***********************************************************************************************************************
  151. ok: [172.31.41.110]
  152.  
  153. TASK [install httpd] ***********************************************************************************************************************
  154. changed: [172.31.41.110]
  155.  
  156. TASK [creating conf file from template file] ***************************************************************************************************
  157. changed: [172.31.41.110]
  158.  
  159. TASK [creating virtualhost from template file] *************************************************************************************************
  160. changed: [172.31.41.110]
  161.  
  162. TASK [creating document root] ******************************************************************************************************************
  163. changed: [172.31.41.110]
  164.  
  165. TASK [create index file] ***********************************************************************************************************************
  166. changed: [172.31.41.110]
  167.  
  168. PLAY RECAP ***********************************************************************************************************************
  169. 172.31.41.110 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  170.  
  171.  
  172. $ ansible -i hosts all -b -m shell -a "yum remove httpd -y ; rm -rf /etc/httpd/* /var/www/html/*"
  173.  
  174.  
  175.  
  176.  
  177. $ cat site.yml
  178. ---
  179.  
  180. - name: "simple site hosting"
  181. become: yes
  182. hosts: amazon
  183. vars:
  184. httpd_owner: apache
  185. httpd_group: apache
  186. httpd_port: 80
  187. httpd_domain: mysite.1by2.online
  188. tasks:
  189.  
  190. - name: "install httpd"
  191. yum:
  192. name: httpd
  193. state: present
  194.  
  195. - name: "creating conf file from template file"
  196. template:
  197. src: "./httpd.conf.j2"
  198. dest: "/etc/httpd/conf/httpd.conf"
  199. owner: "{{ httpd_owner }}"
  200. group: "{{ httpd_group }}"
  201. notify:
  202. - "apache-restart"
  203.  
  204. - name: "creating virtualhost from template file"
  205. template:
  206. src: "./virtualhost.conf.j2"
  207. dest: "/etc/httpd/conf.d/{{ httpd_domain }}.conf"
  208. owner: "{{ httpd_owner }}"
  209. group: "{{ httpd_group }}"
  210. notify:
  211. - "apache-restart"
  212.  
  213. - name: "creating document root"
  214. file:
  215. path: "/var/www/html/{{ httpd_domain }}"
  216. state: directory
  217. owner: "{{ httpd_owner }}"
  218. group: "{{ httpd_group }}"
  219.  
  220. - name: "create index file"
  221. copy:
  222. content: "<h1><center>{{ ansible_fqdn }} </h1></center>"
  223. dest: "/var/www/html/{{ httpd_domain }}/index.html"
  224. owner: "{{ httpd_owner }}"
  225. group: "{{ httpd_group }}"
  226.  
  227. handlers:
  228. - name: "apache-restart"
  229. service:
  230. name: httpd
  231. state: restarted
  232. enabled: true
  233.  
  234.  
  235.  
  236. $ ansible-playbook -i hosts site.yml
  237.  
  238. PLAY [simple site hosting] *********************************************************************************************************************
  239.  
  240. TASK [Gathering Facts] ***********************************************************************************************************************
  241. ok: [172.31.41.110]
  242.  
  243. TASK [install httpd] ***********************************************************************************************************************
  244. changed: [172.31.41.110]
  245.  
  246. TASK [creating conf file from template file] ***************************************************************************************************
  247. changed: [172.31.41.110]
  248.  
  249. TASK [creating virtualhost from template file] *************************************************************************************************
  250. changed: [172.31.41.110]
  251.  
  252. TASK [creating document root] ******************************************************************************************************************
  253. changed: [172.31.41.110]
  254.  
  255. TASK [create index file] ***********************************************************************************************************************
  256. changed: [172.31.41.110]
  257.  
  258. RUNNING HANDLER [apache-restart] ***************************************************************************************************************
  259. changed: [172.31.41.110]
  260.  
  261. PLAY RECAP ***********************************************************************************************************************
  262. 172.31.41.110 : ok=7 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  263.  
  264.  
  265. $ ansible-playbook -i hosts site.yml
  266.  
  267. PLAY [simple site hosting] *********************************************************************************************************************
  268.  
  269. TASK [Gathering Facts] ***********************************************************************************************************************ok: [172.31.41.110]
  270.  
  271. TASK [install httpd] ***********************************************************************************************************************
  272. ok: [172.31.41.110]
  273.  
  274. TASK [creating conf file from template file] ***************************************************************************************************
  275. ok: [172.31.41.110]
  276.  
  277. TASK [creating virtualhost from template file] *************************************************************************************************
  278. ok: [172.31.41.110]
  279.  
  280. TASK [creating document root] ******************************************************************************************************************
  281. ok: [172.31.41.110]
  282.  
  283. TASK [create index file] ***********************************************************************************************************************
  284. ok: [172.31.41.110]
  285.  
  286. PLAY RECAP ***********************************************************************************************************************
  287. 172.31.41.110 : ok=6 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  288.  
  289.  
  290. =======================================================================================================================
  291.  
  292. $ ansible -i hosts all -b -m shell -a "yum remove httpd -y ; rm -rf /etc/httpd/* /var/www/html/*"
  293.  
  294.  
  295. $ cat site.yml
  296. ---
  297.  
  298. - name: "simple site hosting"
  299. become: yes
  300. hosts: amazon
  301. vars:
  302. httpd_owner: apache
  303. httpd_group: apache
  304. httpd_port: 80
  305. httpd_domain: mysite.1by2.online
  306. tasks:
  307.  
  308. - name: "install httpd"
  309. yum:
  310. name: httpd
  311. state: present
  312.  
  313. - name: "creating conf file from template file"
  314. template:
  315. src: "./httpd.conf.j2"
  316. dest: "/etc/httpd/conf/httpd.conf"
  317. owner: "{{ httpd_owner }}"
  318. group: "{{ httpd_group }}"
  319. notify:
  320. - "apache-restart"
  321. - "php-restart"
  322.  
  323. - name: "creating virtualhost from template file"
  324. template:
  325. src: "./virtualhost.conf.j2"
  326. dest: "/etc/httpd/conf.d/{{ httpd_domain }}.conf"
  327. owner: "{{ httpd_owner }}"
  328. group: "{{ httpd_group }}"
  329. notify:
  330. - "apache-restart"
  331.  
  332. - name: "creating document root"
  333. file:
  334. path: "/var/www/html/{{ httpd_domain }}"
  335. state: directory
  336. owner: "{{ httpd_owner }}"
  337. group: "{{ httpd_group }}"
  338.  
  339. - name: "create index file"
  340. copy:
  341. content: "<h1><center>{{ ansible_fqdn }} </h1></center>"
  342. dest: "/var/www/html/{{ httpd_domain }}/index.html"
  343. owner: "{{ httpd_owner }}"
  344. group: "{{ httpd_group }}"
  345.  
  346. handlers:
  347. - name: "apache-restart"
  348. service:
  349. name: httpd
  350. state: restarted
  351. enabled: true
  352.  
  353. - name: "php-restart"
  354. debug:
  355. msg: "restarting PHP service"
  356.  
  357.  
  358.  
  359. $ ansible-playbook -i hosts site.yml
  360.  
  361. PLAY [simple site hosting] *********************************************************************************************************************
  362.  
  363. TASK [Gathering Facts] ***********************************************************************************************************************
  364. ok: [172.31.41.110]
  365.  
  366. TASK [install httpd] ***********************************************************************************************************************
  367. changed: [172.31.41.110]
  368.  
  369. TASK [creating conf file from template file] ***************************************************************************************************
  370. changed: [172.31.41.110]
  371.  
  372. TASK [creating virtualhost from template file] *************************************************************************************************
  373. changed: [172.31.41.110]
  374.  
  375. TASK [creating document root] ******************************************************************************************************************
  376. changed: [172.31.41.110]
  377.  
  378. TASK [create index file] ***********************************************************************************************************************
  379. changed: [172.31.41.110]
  380.  
  381. RUNNING HANDLER [apache-restart] ***************************************************************************************************************
  382. changed: [172.31.41.110]
  383.  
  384. RUNNING HANDLER [php-restart] ******************************************************************************************************************
  385. ok: [172.31.41.110] => {
  386. "msg": "restarting PHP service"
  387. }
  388.  
  389. PLAY RECAP ***********************************************************************************************************************
  390. 172.31.41.110 : ok=8 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  391.  
  392.  
  393.  
  394. $ cat virtualhost.conf.j2
  395. <VirtualHost *:{{ httpd_port }}>
  396. ServerName {{ httpd_domain }}
  397. DocumentRoot /var/www/html/{{ httpd_domain }}
  398. DirectoryIndex index.html index.php index.jsp
  399.  
  400. <Directory "/var/www/html/{{ httpd_domain }}">
  401. AllowOverride all
  402. </Directory>
  403. </VirtualHost>
  404.  
  405.  
  406. $ ansible-playbook -i hosts site.yml
  407.  
  408. PLAY [simple site hosting] *****************************************************
  409.  
  410. TASK [Gathering Facts] *********************************************************
  411. ok: [172.31.41.110]
  412.  
  413. TASK [install httpd] ***********************************************************
  414. ok: [172.31.41.110]
  415.  
  416. TASK [creating conf file from template file] ***********************************
  417. ok: [172.31.41.110]
  418.  
  419. TASK [creating virtualhost from template file] *********************************
  420. changed: [172.31.41.110]
  421.  
  422. TASK [creating document root] **************************************************
  423. ok: [172.31.41.110]
  424.  
  425. TASK [create index file] *******************************************************
  426. ok: [172.31.41.110]
  427.  
  428. RUNNING HANDLER [apache-restart] ***********************************************
  429. changed: [172.31.41.110]
  430.  
  431. PLAY RECAP *********************************************************************
  432. 172.31.41.110 : ok=7 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
  433.  
  434.  
  435.  
  436. =======================================================================================================================
  437.  
  438.  
  439.  
  440. # cat /etc/ansible/ansible.cfg | grep roles_path
  441. roles_path = /etc/ansible/roles
  442.  
  443.  
  444. # cd /etc/ansible/roles/
  445. # ls -l
  446. total 0
  447. # yum install tree -y &> /dev/null
  448. # ansible-galaxy init lamp
  449. - Role lamp was created successfully
  450.  
  451. # tree lamp/
  452. lamp/
  453. ├── defaults
  454. │   └── main.yml
  455. ├── files
  456. ├── handlers
  457. │   └── main.yml
  458. ├── meta
  459. │   └── main.yml
  460. ├── README.md
  461. ├── tasks
  462. │   └── main.yml
  463. ├── templates
  464. ├── tests
  465. │   ├── inventory
  466. │   └── test.yml
  467. └── vars
  468. └── main.yml
  469.  
  470. 8 directories, 8 files
  471.  
  472.  
  473.  
  474. # cat lamp/vars/main.yml
  475. ---
  476.  
  477. httpd_owner: apache
  478. httpd_group: apache
  479. httpd_port: 80
  480. httpd_domain: mysite.1by2.online
  481. mariadb_root_pass: admin123
  482. mariadb_extra_user: wp_user
  483. mariadb_extra_pass: wp_user_pass
  484. mariadb_extra_db: wp_db
  485. wp_url: https://wordpress.org/wordpress-6.0.3.tar.gz
  486.  
  487.  
  488. # cat lamp/files/test.php
  489. <?php phpinfo(); ?>
  490.  
  491. # cat lamp/files/test.html
  492. <h1><center>apache is working</center></h1>
  493.  
  494.  
  495.  
  496. # tree lamp/
  497. lamp/
  498. ├── defaults
  499. │   └── main.yml
  500. ├── files
  501. │   ├── test.html
  502. │   └── test.php
  503. ├── handlers
  504. │   └── main.yml
  505. ├── meta
  506. │   └── main.yml
  507. ├── README.md
  508. ├── tasks
  509. │   └── main.yml
  510. ├── templates
  511. ├── tests
  512. │   ├── inventory
  513. │   └── test.yml
  514. └── vars
  515. └── main.yml
  516.  
  517. 8 directories, 10 files
  518.  
  519.  
  520. # cp /home/ec2-user/*.j2 lamp/templates/
  521.  
  522. # tree lamp/
  523. lamp/
  524. ├── defaults
  525. │   └── main.yml
  526. ├── files
  527. │   ├── test.html
  528. │   └── test.php
  529. ├── handlers
  530. │   └── main.yml
  531. ├── meta
  532. │   └── main.yml
  533. ├── README.md
  534. ├── tasks
  535. │   └── main.yml
  536. ├── templates
  537. │   ├── httpd.conf.j2
  538. │   ├── virtualhost.conf.j2
  539. │   └── wp-config.php.j2
  540. ├── tests
  541. │   ├── inventory
  542. │   └── test.yml
  543. └── vars
  544. └── main.yml
  545.  
  546. 8 directories, 13 files
  547.  
  548.  
  549.  
  550. # cat lamp/handlers/main.yml
  551. ---
  552.  
  553. - name: "apache-restart"
  554. service:
  555. name: httpd
  556. state: restarted
  557. enabled: true
  558.  
  559.  
  560. # cat lamp/tasks/main.yml
  561. ---
  562.  
  563. - name: "installing httpd"
  564. yum:
  565. name: httpd
  566. state: present
  567.  
  568. - name: "installing php"
  569. shell: amazon-linux-extras install php7.4 -y
  570. notify:
  571. - "apache-restart"
  572.  
  573. - name: "creating conf file from template file"
  574. template:
  575. src: "./httpd.conf.j2"
  576. dest: "/etc/httpd/conf/httpd.conf"
  577. owner: "{{ httpd_owner }}"
  578. group: "{{ httpd_group }}"
  579. notify:
  580. - "apache-restart"
  581.  
  582. - name: "creating virtualhost from template file"
  583. template:
  584. src: "./virtualhost.conf.j2"
  585. dest: "/etc/httpd/conf.d/{{ httpd_domain }}.conf"
  586. owner: "{{ httpd_owner }}"
  587. group: "{{ httpd_group }}"
  588. notify:
  589. - "apache-restart"
  590.  
  591. - name: "creating document root"
  592. file:
  593. path: "/var/www/html/{{ httpd_domain }}"
  594. state: directory
  595. owner: "{{ httpd_owner }}"
  596. group: "{{ httpd_group }}"
  597.  
  598. - name: "creating sample files"
  599. copy:
  600. src: "{{ item }}"
  601. dest: "/var/www/html/{{ httpd_domain }}/"
  602. owner: "{{ httpd_owner }}"
  603. group: "{{ httpd_group }}"
  604. with_items:
  605. - test.php
  606. - test.html
  607.  
  608. - name: "Mariadb - installing package"
  609. yum:
  610. name:
  611. - mariadb-server
  612. - MySQL-python
  613. state: present
  614.  
  615. - name: "Mariadb - restarting & enabling service"
  616. service:
  617. name: mariadb
  618. state: restarted
  619. enabled: true
  620.  
  621. - name: "Mariadb - updating root pass"
  622. ignore_errors: true
  623. mysql_user:
  624. login_user: root
  625. login_password: ""
  626. name: root
  627. password: "{{ mariadb_root_pass }}"
  628. host_all: true
  629.  
  630. - name: "Mariadb - removing anonymous users"
  631. mysql_user:
  632. login_user: root
  633. login_password: "{{ mariadb_root_pass }}"
  634. name: ""
  635. password: ""
  636. host_all: true
  637. state: absent
  638.  
  639. - name: "Mariadb - creating db"
  640. mysql_db:
  641. login_user: root
  642. login_password: "{{ mariadb_root_pass }}"
  643. name: "{{ mariadb_extra_db }}"
  644. state: present
  645.  
  646. - name: "Mariadb - creating user"
  647. mysql_user:
  648. login_user: root
  649. login_password: "{{ mariadb_root_pass }}"
  650. name: "{{ mariadb_extra_user }}"
  651. password: "{{ mariadb_extra_pass }}"
  652. state: present
  653. host: "%"
  654. priv: "{{ mariadb_extra_db }}.*:ALL"
  655.  
  656.  
  657.  
  658. =======================================================================================================================
  659. # ansible-galaxy init update
  660. - Role update was created successfully
  661.  
  662. # tree update/
  663. update/
  664. ├── defaults
  665. │   └── main.yml
  666. ├── files
  667. ├── handlers
  668. │   └── main.yml
  669. ├── meta
  670. │   └── main.yml
  671. ├── README.md
  672. ├── tasks
  673. │   └── main.yml
  674. ├── templates
  675. ├── tests
  676. │   ├── inventory
  677. │   └── test.yml
  678. └── vars
  679. └── main.yml
  680.  
  681. 8 directories, 8 files
  682.  
  683.  
  684.  
  685. # cat update/tasks/main.yml
  686. ---
  687.  
  688. - name: "updating - {{ ansible_os_family }}"
  689. when: ansible_distribution == "Amazon" and ansible_os_family == "RedHat"
  690. yum:
  691. name: "*"
  692. state: latest
  693.  
  694. - name: "updating - {{ ansible_os_family }}"
  695. when: ansible_distribution == "Ubuntu" and ansible_os_family == "Debian"
  696. apt:
  697. name: "*"
  698. state: latest
  699. update_cache: true
  700.  
  701.  
  702.  
  703. # logout
  704.  
  705. $ whoami
  706. ec2-user
  707.  
  708. $ pwd
  709. /home/ec2-user
  710.  
  711.  
  712. $ cat main.yml
  713. ---
  714.  
  715. - name: "demo role"
  716. hosts: all
  717. become: true
  718. roles:
  719. - update
  720. - lamp
  721.  
  722.  
  723.  
  724. $ ansible-playbook -i hosts main.yml
  725.  
  726. PLAY [demo role] ***************************************************************
  727.  
  728. TASK [Gathering Facts] *********************************************************
  729. ok: [172.31.41.110]
  730.  
  731. TASK [update : updating - RedHat] **********************************************
  732. ok: [172.31.41.110]
  733.  
  734. TASK [update : updating - RedHat] **********************************************
  735. skipping: [172.31.41.110]
  736.  
  737. TASK [lamp : installing httpd] *************************************************
  738. ok: [172.31.41.110]
  739.  
  740. TASK [lamp : installing php] ***************************************************
  741. changed: [172.31.41.110]
  742.  
  743. TASK [lamp : creating conf file from template file] ****************************
  744. ok: [172.31.41.110]
  745.  
  746. TASK [lamp : creating virtualhost from template file] **************************
  747. ok: [172.31.41.110]
  748.  
  749. TASK [lamp : creating document root] *******************************************
  750. ok: [172.31.41.110]
  751.  
  752. TASK [lamp : creating sample files] ********************************************
  753. changed: [172.31.41.110] => (item=test.php)
  754. changed: [172.31.41.110] => (item=test.html)
  755.  
  756. TASK [lamp : Mariadb - installing package] *************************************
  757. changed: [172.31.41.110]
  758.  
  759. TASK [lamp : Mariadb - restarting & enabling service] **************************
  760. changed: [172.31.41.110]
  761.  
  762. TASK [lamp : Mariadb - updating root pass] *************************************
  763. changed: [172.31.41.110]
  764.  
  765. TASK [lamp : Mariadb - removing anonymous users] *******************************
  766. changed: [172.31.41.110]
  767.  
  768. TASK [lamp : Mariadb - creating db] ********************************************
  769. changed: [172.31.41.110]
  770.  
  771. TASK [lamp : Mariadb - creating user] ******************************************
  772. changed: [172.31.41.110]
  773.  
  774. RUNNING HANDLER [lamp : apache-restart] ****************************************
  775. changed: [172.31.41.110]
  776.  
  777. PLAY RECAP *********************************************************************
  778. 172.31.41.110 : ok=15 changed=9 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
  779.  
  780.  
  781.  
  782.  
  783. $ cat wp-config.php.j2
  784.  
  785. define(‘DB_NAME’, '{{ mariadb_extra_db }}');
  786. define(‘DB_USER’, '{{ mariadb_extra_user }}');
  787. define(‘DB_PASSWORD’, '{{ mariadb_extra_pass }}');
  788. define(‘DB_HOST’, ‘localhost’);
  789.  
  790.  
  791.  
  792. $ cat main.yml
  793. ---
  794.  
  795. - name: "demo role"
  796. hosts: all
  797. become: true
  798. roles:
  799. - update
  800. - lamp
  801.  
  802. tasks:
  803.  
  804. - name: "Wordpress - downloading archive"
  805. get_url:
  806. url: "{{ wp_url }}"
  807. dest: "/tmp/wordpress.tar.gz"
  808.  
  809. - name: "Wordpress - extracting archive"
  810. unarchive:
  811. src: "/tmp/wordpress.tar.gz"
  812. dest: "/tmp/"
  813. remote_src: true
  814.  
  815. - name: "Wordpress - copying files"
  816. copy:
  817. src: "/tmp/wordpress/"
  818. dest: "/var/www/html/{{ httpd_domain }}/"
  819. remote_src: true
  820. owner: "{{ httpd_owner }}"
  821. group: "{{ httpd_group }}"
  822.  
  823. - name: "Wordpress - creating wp-config file from template"
  824. template:
  825. src: "./wp-config.php.j2"
  826. dest: "/var/www/html/{{ httpd_domain }}/wp-config.php"
  827. owner: "{{ httpd_owner }}"
  828. group: "{{ httpd_group }}"
  829.  
  830. - name: "Post Installation - restarting"
  831. service:
  832. name: "{{ item }}"
  833. state: restarted
  834. enabled: true
  835. with_items:
  836. - httpd
  837. - mariadb
  838.  
  839. - name: "Post Installation - cleanup"
  840. file:
  841. name: "{{ item }}"
  842. state: absent
  843. with_items:
  844. - "/tmp/wordpress/"
  845. - "/tmp/wordpress.tar.gz"
  846.  
  847.  
  848. $ ansible -i hosts all -b -m shell -a "yum remove httpd php-* mariadb-server -y ; rm -rf /etc/httpd/* /var/www/html/* /var/lib/mysql/*"
  849.  
  850.  
  851. $ ansible-playbook -i hosts main.yml
  852.  
  853. PLAY [demo role] ***********************************************************************************************************************
  854.  
  855. TASK [Gathering Facts] ***********************************************************************************************************************
  856. ok: [172.31.41.110]
  857.  
  858. TASK [update : updating - RedHat] **************************************************************************************************************
  859. ok: [172.31.41.110]
  860.  
  861. TASK [update : updating - RedHat] **************************************************************************************************************
  862. skipping: [172.31.41.110]
  863.  
  864. TASK [lamp : installing httpd] *****************************************************************************************************************
  865. changed: [172.31.41.110]
  866.  
  867. TASK [lamp : installing php] *******************************************************************************************************************
  868. changed: [172.31.41.110]
  869.  
  870. TASK [lamp : creating conf file from template file] ********************************************************************************************
  871. changed: [172.31.41.110]
  872.  
  873. TASK [lamp : creating virtualhost from template file] ******************************************************************************************
  874. changed: [172.31.41.110]
  875.  
  876. TASK [lamp : creating document root] ***********************************************************************************************************
  877. changed: [172.31.41.110]
  878.  
  879. TASK [lamp : creating sample files] ************************************************************************************************************
  880. changed: [172.31.41.110] => (item=test.php)
  881. changed: [172.31.41.110] => (item=test.html)
  882.  
  883. TASK [lamp : Mariadb - installing package] *****************************************************************************************************
  884. changed: [172.31.41.110]
  885.  
  886. TASK [lamp : Mariadb - restarting & enabling service] ******************************************************************************************
  887. changed: [172.31.41.110]
  888.  
  889. TASK [lamp : Mariadb - updating root pass] *****************************************************************************************************
  890. changed: [172.31.41.110]
  891.  
  892. TASK [lamp : Mariadb - removing anonymous users] ***********************************************************************************************
  893. changed: [172.31.41.110]
  894.  
  895. TASK [lamp : Mariadb - creating db] ************************************************************************************************************
  896. changed: [172.31.41.110]
  897.  
  898. TASK [lamp : Mariadb - creating user] **********************************************************************************************************
  899. changed: [172.31.41.110]
  900.  
  901. TASK [Wordpress - downloading archive] *********************************************************************************************************
  902. changed: [172.31.41.110]
  903.  
  904. TASK [Wordpress - extracting archive] **********************************************************************************************************
  905. changed: [172.31.41.110]
  906.  
  907. TASK [Wordpress - copying files] ***************************************************************************************************************
  908. changed: [172.31.41.110]
  909.  
  910. TASK [Wordpress - creating wp-config file from template] ***************************************************************************************
  911. changed: [172.31.41.110]
  912.  
  913. TASK [Post Installation - restarting] **********************************************************************************************************
  914. changed: [172.31.41.110] => (item=httpd)
  915. changed: [172.31.41.110] => (item=mariadb)
  916.  
  917. TASK [Post Installation - cleanup] *************************************************************************************************************
  918. changed: [172.31.41.110] => (item=/tmp/wordpress/)
  919. changed: [172.31.41.110] => (item=/tmp/wordpress.tar.gz)
  920.  
  921. RUNNING HANDLER [lamp : apache-restart] ********************************************************************************************************
  922. changed: [172.31.41.110]
  923.  
  924. PLAY RECAP ***********************************************************************************************************************
  925. 172.31.41.110 : ok=21 changed=19 unreachable=0 failed=0 skipped=1 rescued=0 ignored=0
  926.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement