- name: Import nginx signing key
  become: yes
  apt_key:
    url: https://nginx.org/keys/nginx_signing.key
    state: present

- name: Add nginx stable repo
  become: yes
  copy:
    dest: /etc/apt/sources.list.d/nginx.list
    owner: root
    group: root
    mode: '0644'
    content: deb https://nginx.org/packages/{{ distro_family }} {{ distro_codename }} nginx
  vars:
    distro_family: "{{ ansible_distribution | lower }}"
    distro_codename: "{{ ansible_distribution_release }}"

- name: Update apt cache
  become: yes
  apt:
    update_cache: yes
    cache_valid_time: 3600
  register: apt_update_cache
  retries: 5
  delay: 60
  until: apt_update_cache is succeeded
