---
- name: Dependencies installed
  community.general.pkgng:
    name: nginx
    state: latest

- name: Nginx enabled
  shell: sysrc nginx_enable="YES"

- name: Nginx locations folder exists
  file: path=/usr/local/etc/nginx/locations/ state=directory

- name: Nginx sites folder exists
  file: path=/usr/local/etc/nginx/sites/ state=directory

- name: Nginx config installed
  template:
    src: nginx.conf.j2
    dest: /usr/local/etc/nginx/nginx.conf
    mode: 0644
  notify: Nginx restarted

- name: Ensure nginx is running
  service:
    name: nginx
    state: started
