---
# ------------------------------------------------------------------------------
# These tasks run for ALL servers be it Debian, CentOS, Virtual or Physical
# ------------------------------------------------------------------------------

# Copy profiles to /etc/profile.d/
- include_tasks: ../../../shared/functions/copy_etc-profile.d.yml

# Copy scripts to /usr/local/bin
- include_tasks: ../../../shared/functions/copy_usr-local-bin.yml

# Rsync /etc/vim
- name: Synchronizing /etc/vim
  synchronize:
    src: vim/vim
    dest: /etc/
    delete: yes
    group: no
    owner: no
    rsync_opts:
      - "--exclude=.git"

- name: Sed /etc/vim/vimrc
  replace:
    path: /etc/vim/vimrc
    regexp: '~/.vim/plugged'
    replace: '/etc/vim/plugged'

- name: Symlink /usr/share/vim/vimfiles
  file:
    src: /etc/vim
    dest: /usr/share/vim/vimfiles
    owner: root
    group: root
    state: link
  when: ansible_os_family == "Debian"

# Increase number of TCP connections per port (debian default 128)
- name: Increasing number of TCP connections per port /etc/sysctl.conf net.core.somaxconn = 4096
  sysctl:
    name: net.core.somaxconn
    value: '4096'
    reload: yes
    state: present

# Increase open files (ulimit), default debian 1024
# View ulimit -a
- name: Increase soft open file limit (ulimit)
  pam_limits:
    domain: '*'
    limit_type: soft
    limit_item: nofile
    value: '65535'
- name: Increase hard open file limit (ulimit)
  pam_limits:
    domain: '*'
    limit_type: hard
    limit_item: nofile
    value: '65535'

# Increase max_user_watches
# View with sysctl -a |grep max_user_watches (default on debian is 8192)
- name: Increase fs.inotify.max_user_watches in /etc/sysctl.conf
  sysctl:
    name: fs.inotify.max_user_watches
    value: '524288'
    reload: yes
    state: present
