---
- name: Add nginx key
  become: yes
  rpm_key:
    key: http://nginx.org/keys/nginx_signing.key
    state: present
  tags: nginx

- name: Add nginx repos
  become: yes
  yum_repository:
    name: nginx
    description: nginx repo
    baseurl: http://nginx.org/packages/rhel/{{ ansible_distribution_major_version }}/x86_64/
    gpgcheck: yes
    enabled: yes
    state: present
  tags: nginx

- name: Install nginx
  become: yes
  yum:
    name: nginx
    state: present
  tags: nginx

- name: Install dependencies for SELinux Ansible module
  become: yes
  yum:
    name: libsemanage-python, libselinux-python
    state: present
  register: nginx_selinux_dependencies
  tags: nginx

- name: Update SELinux facts after installing dependencies
  become: yes
  setup:
    filter: ansible_selinux
  when: nginx_selinux_dependencies.changed
  tags: nginx

- name: Adjust SELinux to allow network access for nginx
  become: yes
  seboolean:
    name: httpd_can_network_connect
    state: yes
    persistent: yes
  when: ansible_selinux.status == "enabled" and ansible_selinux.mode == "enforcing"
  tags: nginx

---
- name: Add nginx key
  become: yes
  rpm_key:
    key: http://nginx.org/keys/nginx_signing.key
    state: present
  tags: nginx

- name: Add nginx repos
  become: yes
  yum_repository:
    name: nginx
    description: nginx repo
    baseurl: http://nginx.org/packages/rhel/{{ ansible_distribution_major_version }}/x86_64/
    gpgcheck: yes
    enabled: yes
    state: present
  tags: nginx

- name: Install nginx
  become: yes
  yum:
    name: nginx
    state: present
  tags: nginx

- name: Remove default site
  become: yes
  file:
    path: /etc/nginx/conf.d/default.conf
    state: absent
  tags: nginx

- name: Install dependencies for SELinux Ansible module
  become: yes
  yum:
    name: libsemanage-python, libselinux-python
    state: present
  register: nginx_selinux_dependencies
  tags: nginx

- name: Update SELinux facts after installing dependencies
  become: yes
  setup:
    filter: ansible_selinux
  when: nginx_selinux_dependencies.changed
  tags: nginx

- name: Adjust SELinux to allow network access for nginx
  become: yes
  seboolean:
    name: httpd_can_network_connect
    state: yes
    persistent: yes
  when: ansible_selinux.status == "enabled" and ansible_selinux.mode == "enforcing"
  tags: nginx

Remove default nginx site for EL
Remove default nginx site for EL

/etc/nginx/conf.d/default.conf can exist in some configurations
