Advertisement
sandervanvugt

Untitled

Jun 18th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. [ansible@control lesson8]$ cat chad.yml
  2. ---
  3. - name: create local index.html file
  4. hosts: localhost
  5. tasks:
  6. - name: create local index.html file
  7. copy:
  8. dest: /tmp/index.html
  9. content: "Welcome to my webserver."
  10.  
  11. - name: install and configure web server
  12. hosts: ansible2.example.com
  13. vars_files:
  14. - vars/web_vars
  15. tasks:
  16. - name: install packages
  17. yum:
  18. name: "{{ web_packages }}"
  19. when:
  20. - ansible_distribution in supported_distros
  21. - ansible_distribution != "Fedora"
  22. - ansible_distribution_major_version == "8"
  23. - name: fail when run on fedora or older supported distros
  24. fail:
  25. msg: >
  26. Host {{ ansible_facts['hostname'] }} does not meet minimal requirements
  27. when:
  28. ( ansible_distribution not in supported_distros ) or ( ansible_distribution_major_version != "8" )
  29.  
  30. - name: configure web content
  31. block:
  32. - name: copy index.html
  33. copy:
  34. src: /tmp/index.html
  35. dest: /var/www/html/
  36. owner: apache
  37. group: apache
  38. mode: 0644
  39. notify: restart httpd
  40. rescue:
  41. - debug:
  42. msg: >
  43. There was an issue copying the index.html file
  44. - name: configure firewall
  45. firewalld:
  46. service: "{{ item }}"
  47. state: enabled
  48. permanent: true
  49. immediate: true
  50. loop:
  51. - http
  52. - https
  53. handlers:
  54. - name: restart httpd
  55. service:
  56. name: httpd
  57. state: restarted
  58. ...
  59. [ansible@control lesson8]$
  60. [ansible@control lesson8]$ cat vars/web_vars
  61. web_packages:
  62. - httpd
  63. - mod_ssl
  64. supported_distros:
  65. - "RedHat"
  66. - "CentOS"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement