sandervanvugt

ansible: fix this playbook

Oct 7th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. [ansible@control lesson8]$ cat lab2.yaml
  2. ---
  3. - name: deploy httpd
  4. hosts: ansible2.example.com
  5. vars_files:
  6. - packages.yml
  7. vars:
  8. supported_distros:
  9. - CentOS
  10. - RedHat
  11. tasks:
  12. - name: setting up httpd service
  13. block:
  14. - name: Install web packages
  15. yum:
  16. name: "{{ item }}"
  17. state: present
  18. loop: "{{ webpackages }}"
  19. become: yes
  20. - name: enable and start httpd
  21. service:
  22. name: httpd
  23. enabled: true
  24. state: started
  25. become: yes
  26. - name: allow http and https
  27. firewalld:
  28. service: "{{ item }}"
  29. permanent: true
  30. immediate: true
  31. state: enabled
  32. loop:
  33. - http
  34. - https
  35. become: yes
  36. when: ansible_facts['distribution'] in supported_distros and ansible_facts['distribution_version'] >= "8"
  37. - debug:
  38. msg: echo "Host {{ ansible_facts['hostname'] }} does not meet minimal requirements"
  39. when: ansible_facts['distribution'] not in supported_distros or ansible_facts['distribution_version'] < "8"
  40.  
  41. - name: create index.html in local /tmp
  42. hosts: localhost
  43. tasks:
  44. - name: create Index.html in local /tmp
  45. copy:
  46. content: "Welcome to my webserver"
  47. dest: /tmp/index.html
  48. owner: root
  49. group: root
  50.  
  51. - name: deploy index.html
  52. hosts: ansible2.example.com
  53. tasks:
  54. - name: copy index.html to /var/www/html
  55. copy:
  56. src: /tmp/index.html
  57. dest: /var/www/html
  58. owner: root
  59. group: root
  60. mode: "0644"
  61. register: command_result
  62. notify:
  63. - restart_web
  64. - name: debugging
  65. debug:
  66. var: command_result
  67. - debug:
  68. msg: echo "Failed copying index.html to {{ ansible_facts['hostname'] }}"
  69. when: not command_result.changed
  70. handlers:
  71. - name: restart_web
  72. service:
  73. name: httpd
  74. state: restarted
  75.  
  76. [ansible@control lesson8]$ cat packages.yml
  77. webpackages:
  78. - httpd
  79. - mod_ssl
Add Comment
Please, Sign In to add comment