- import_tasks: init.yml

- name: add PPA for Ubuntu Toolchain
  become: true
  ansible.builtin.apt_repository:
    repo: ppa:ubuntu-toolchain-r/test
  when: ansible_distribution == 'Ubuntu'

# https://classic.yarnpkg.com/lang/en/docs/install/#debian-stable
- name: Add an yarn signing key
  become: true
  ansible.builtin.apt_key:
    url: https://dl.yarnpkg.com/debian/pubkey.gpg
    state: present
  when: ansible_distribution == 'Ubuntu'

- name: Add an yarn package repository
  become: true
  ansible.builtin.lineinfile:
    path: /etc/apt/sources.list.d/yarn.list
    line: "deb https://dl.yarnpkg.com/debian/ stable main"
    create: true
  when: ansible_distribution == 'Ubuntu'

- name: Install nodejs
  become: true
  community.general.snap:
    name: node
    classic: true

- name: Update system
  become: true
  apt:
    upgrade: yes
    update_cache: yes
    cache_valid_time: 3600

- name: Install dependicy packages
  become: true
  apt:
    pkg:
      - apt-transport-https
      - software-properties-common
      - gnupg
      - openssh-server
      - openssh-client
      - sshpass
      - wpasupplicant
      - rsync
      - at
      - sysstat
      - libtool
      - ethtool
      - dnsutils
      - dnsmasq
      - uuid-runtime
      - lshw
      - tcpdump
      - lm-sensors
      - dmidecode
      - net-tools
      - iputils-arping
      - iputils-ping
      - telnet
      - vim
      - git
      - pwgen
      - locales
      - ntpdate
      - imagemagick
      - mpg123
      - ffmpeg
      - sqlite3
      - tree
      - alsa-utils
      - pulseaudio
      - zsh
      - wget
      - curl
      - zip
      - unzip
      - nginx
      - libnginx-mod-http-upstream-fair
      - certbot
      - python3-certbot-nginx
      - openvpn
      - snmpd
      - mutt
      - systemd-cron
      - screen
      - tmux
      - hugo
      - yarn
      - python3
      - python3-pip
      - python3-distutils
      - python3-dev
      - libssl-dev
      - libpq-dev
      - libmysqlclient-dev
      - libevent-dev

- name: Install dependicy packages(>bionic)
  become: true
  apt:
    pkg:
      - systemd-timesyncd
  # ansible_facts['distribution'] == "Ubuntu"
  when: ansible_facts['distribution_major_version'] | int >= 20

- import_tasks: locales.yml

- name: Set default editor to vim
  become: true
  shell: update-alternatives --set editor /usr/bin/vim.basic

- name: Set timezone
  become: true
  shell: timedatectl set-timezone UTC

- name: Set git rebase mode
  become: true
  shell: git config --global pull.rebase false

- import_tasks: zsh.yml

# ---------------------------------------------------

- name: enable nginx service
  become: true
  ansible.builtin.systemd:
    name: nginx
    enabled: yes
    masked: no

- name: enable cron service
  become: true
  ansible.builtin.systemd:
    name: cron
    enabled: yes
    masked: no

- name: enable ssh service
  become: true
  ansible.builtin.systemd:
    name: ssh
    enabled: yes
    masked: no

- name: enable systemd-timesyncd service
  become: true
  ansible.builtin.systemd:
    name: systemd-timesyncd
    enabled: yes
    masked: no

- import_tasks: clean.yml
