main.yml 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ---
  2. # Variable setup.
  3. - name: Include OS-specific variables.
  4. include_vars: "{{ ansible_os_family }}.yml"
  5. - name: Define nginx_user.
  6. set_fact:
  7. nginx_user: "{{ __nginx_user }}"
  8. when: nginx_user is not defined
  9. # Nginx setup.
  10. - name: Enable nginx repo (RedHat).
  11. copy:
  12. src: nginx.repo
  13. dest: /etc/yum.repos.d/nginx.repo
  14. owner: root
  15. group: root
  16. mode: 0644
  17. when: ansible_os_family == 'RedHat'
  18. - name: Ensure nginx is installed (RedHat).
  19. yum: pkg=nginx state=installed enablerepo=nginx
  20. when: ansible_os_family == 'RedHat'
  21. - name: Ensure nginx is installed (Debian).
  22. apt: pkg=nginx state=installed
  23. when: ansible_os_family == 'Debian'
  24. - name: Copy nginx configuration in place.
  25. template:
  26. src: nginx.conf.j2
  27. dest: /etc/nginx/nginx.conf
  28. owner: root
  29. group: root
  30. mode: 0644
  31. notify: restart nginx
  32. - name: Ensure nginx is started and enabled to start at boot.
  33. service: name=nginx state=started enabled=yes
  34. - name: Remove default nginx config file (if configured).
  35. file:
  36. path: "{{ nginx_default_vhost_path }}"
  37. state: absent
  38. when: nginx_remove_default_vhost
  39. notify: restart nginx