---
# tasks file for install_nginx

- name: update packages
  yum:
    name: '*'
    state: latest

- name: install latest epel-release
  command: amazon-linux-extras install epel
  become_method: sudo

- name: install nginx
  yum:
    name: nginx
    state: present

- name: start and enable nginx
  service:
    name: nginx
    state: started
    enabled: true

- name: copy nginx.conf template
  template:
    src: nginx.conf.j2
    dest: /etc/nginx/nginx.conf
  notify: restart nginx

- name: clear contents of /usr/share/nginx/html/ folder
  file:
    path: "{{ item }}"
    state: absent
  with_items:
    - /usr/share/nginx/html/404.html
    - /usr/share/nginx/html/50x.html
    - /usr/share/nginx/html/nginx-logo.png
    - /usr/share/nginx/html/poweredby.png

- name: copy index.html file
  file:
    src: index.html
    dest: /usr/share/nginx/html/index.html
  notify: restart nginx
---
# tasks file for install_nginx

- name: update packages
  yum:
    name: '*'
    state: latest

- name: install latest epel-release
  command: amazon-linux-extras install epel
  become_method: sudo

- name: install nginx
  yum:
    name: nginx
    state: present

- name: start and enable nginx
  service:
    name: nginx
    state: started
    enabled: true

- name: copy nginx.conf template
  template:
    src: nginx.conf.j2
    dest: /etc/nginx/nginx.conf
  notify: restart nginx

- name: clear contents of /usr/share/nginx/html/ folder
  file:
    path: "{{ item }}"
    state: absent
  with_items:
    - /usr/share/nginx/html/404.html
    - /usr/share/nginx/html/50x.html
    - /usr/share/nginx/html/nginx-logo.png
    - /usr/share/nginx/html/poweredby.png

- name: copy index.html file
  copy:
    src: index.html
    dest: /usr/share/nginx/html/index.html
  notify: restart nginx
Copy module instead of file module
Copy module instead of file module
