deploy-httpd.yml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ---
  2. - name: make sure required software is installed
  3. hosts: serverd.lab.example.com
  4. become: yes
  5. gather_facts: no
  6. tasks:
  7. - name: ensure the software is there
  8. yum:
  9. name: httpd
  10. state: latest
  11. - name: ensure that server admin is correctly set
  12. lineinfile:
  13. path: /etc/httpd/conf/httpd.conf
  14. regexp: '^\s*ServerAdmin\s'
  15. line: ServerAdmin webmaster@example.com
  16. notify: them handlerz
  17. - name: ensure that server is configured for port 80
  18. lineinfile:
  19. path: /etc/httpd/conf/httpd.conf
  20. regexp: '^\s*Listen\s'
  21. line: Listen 80
  22. notify: them handlerz
  23. - name: ensure we have a starting block delimiter
  24. lineinfile:
  25. path: /etc/httpd/conf/httpd.conf
  26. insertbefore: '^<Directory "/var/www/html">'
  27. line: "# **** THIS BLOCK IS MANAGED BY ANSIBLE. ANY CHANGES WILL BE REVERTED. ****"
  28. - name: ensure default webroot permissions are sane
  29. blockinfile:
  30. path: /etc/httpd/conf/httpd.conf
  31. marker: "{mark}"
  32. marker_begin: "# **** THIS BLOCK IS MANAGED BY ANSIBLE. ANY CHANGES WILL BE REVERTED. ****"
  33. marker_end: "</Directory>"
  34. block: |
  35. <Directory "/var/www/html">
  36. Options FollowSymLinks
  37. DirectoryIndex index.html
  38. AllowOverride none
  39. Require all granted
  40. notify: them handlerz
  41. - name: ensure the service is started and enabled to start automatically
  42. service:
  43. name: httpd
  44. state: started
  45. enabled: yes
  46. - name: ensure firewall is open for the service
  47. firewalld:
  48. service: http
  49. state: enabled
  50. immediate: yes
  51. permanent: yes
  52. handlers:
  53. - name: test configuration validity
  54. listen: them handlerz
  55. command:
  56. cmd: apachectl configtest
  57. creates: /tmp/was-here-already
  58. chdir: /tmp
  59. changed_when: false
  60. - name: restart the service
  61. listen: them handlerz
  62. service:
  63. name: httpd
  64. state: restarted