main.yml 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 group=root mode=644
  15. when: ansible_os_family == 'RedHat'
  16. - name: Ensure nginx is installed (RedHat).
  17. yum: pkg=nginx state=installed enablerepo=nginx
  18. when: ansible_os_family == 'RedHat'
  19. - name: Ensure nginx is installed (Debian).
  20. apt: pkg=nginx state=installed
  21. when: ansible_os_family == 'Debian'
  22. - name: Copy nginx configuration in place.
  23. template: >
  24. src=nginx.conf.j2
  25. dest=/etc/nginx/nginx.conf
  26. owner=root group=root mode=644
  27. notify: restart nginx
  28. - name: Ensure nginx is started and enabled to start at boot.
  29. service: name=nginx state=started enabled=yes
  30. - name: Remove default nginx config file (if configured).
  31. file: >
  32. path={{ nginx_default_vhost_path }}
  33. state=absent
  34. when: nginx_remove_default_vhost
  35. notify: restart nginx