---

- block:

  - name: Set the max opened files at the system level
    sysctl: name={{ item.name }} value={{ item.value }} state=present
    with_items:
       - { name: "fs.file-max", value: "{{ system_max_open_files_limit }}" }
    when: set_system_max_open_files_limit

  - name: Set max opened files per process
    pam_limits:
      domain: "*"
      limit_item: nofile
      value: "{{ item.value }}"
      limit_type: "{{ item.type }}"
    with_items:
      - { type: "hard", value: "{{ process_max_open_files_limit }}" }
      - { type: "soft", value: "{{ process_max_open_files_limit }}" }

  become: yes
