  - name: "Install python3"
    apt:
      name: python3
      state: present
  - name: "Install python3-pip"
    apt:
      name: python3-pip
      state: present
  - name: "Install python3-virtualenv"
    apt:
      name: python3-virtualenv
      state: present
  - name: "Install  thefuck"
    apt:
      name: thefuck
      state: present
  - name: "Install python3-setuptools"
    apt:
      name: python3-setuptools
      state: present
  - name: "Install nginx"
    apt:
      name: nginx
      state: present
  - name: "Install wget"
    apt:
      name: wget
      state: present
  - name: "Install htop"
    apt:
      name: htop
      state: present
  - name: "Install btop"
    apt:
      name: btop
      state: present
  - name: "Install lynx"
    apt:
      name: lynx
      state: present
  - name: "Install neovim"
    apt:
      name: neovim
      state: present
  - name: "Install docker.io"
    apt:
      name: docker.io
      state: present
  - name: "Install docker-compose"
    apt:
      name: docker-compose
      state: present
  - name: "Install screen"
    apt:
      name: screen
      state: present
  - name: "Install byobu"
    apt:
      name: byobu
      state: present
  - name: "Install zsh"
    apt:
      name: zsh
      state: present
  - name: "Install nmap"
    apt:
      name: nmap
      state: present
  - name: "Install iptraf"
    apt:
      name: iptraf
      state: present
  - name: "Install iotop"
    apt:
      name: iotop
      state: present
  - name: "Install zip"
    apt:
      name: zip
      state: present
  - name: "Install unzip"
    apt:
      name: unzip
      state: present
  - name: "Install net-tools"
    apt:
      name: net-tools
      state: present
  - name: "Install git"
    apt:
      name: git
      state: present
  - name: "Install chkrootkit"
    apt:
      name: chkrootkit
      state: present
  - name: "Install fail2ban"
    apt:
      name: fail2ban
      state: present
  - name: "Install lynis"
    apt:
      name: lynis
      state: present


# thefuck
  - name: "thefuck append to .zshrc"
    lineinfile:
      path: "/home/{{ username }}/.zshrc"
      line: 'eval $(thefuck --alias fuck)'
      insertafter: EOF
      mode: '0744'
      owner: "{{ username }}"
      group: "{{ username }}"
      state: present
      create: True

# PATH
  - name: ".zshrc PATH adding ~/.local/bin"
    lineinfile:
      path: "/home/{{ username }}/.zshrc"
      line: 'PATH=~/.local/bin/:$PATH'
      state: present
      insertafter: EOF
      mode: "0744"
      owner: "{{ username }}"
      group: "{{ username }}"
      create: True
    become: True
    become_method: su
    become_user: "{{ username }}"


# ssh
  - name: "SSH allow {{ username }} only"
    lineinfile:
      path: '/etc/ssh/sshd_config'
      line: "AllowUsers {{ username }}"
      state: present
      insertafter: EOF
      mode: "0644"
      owner: root
      group: root
  - name: 'SSH disable password auth'
    lineinfile:
      path: '/etc/ssh/sshd_config'
      regexp: '^PermitRootLogin'
      line: 'PermitRootLogin no'
      state: present
      insertafter: EOF
      mode: "0644"
      owner: root
      group: root


  - name: "UFW allow ssh"
    community.general.ufw:
      rule: allow
      port: ssh
      proto: tcp
      delete: true
  - name: "UFW allow http"
    community.general.ufw:
      rule: allow
      port: http
      proto: any
      delete: true
  - name: "UFW allow https"
    community.general.ufw:
      rule: allow
      port: https
      proto: any
      delete: true


  - name: 'Customscripts download'
    command:
      cmd: 'git clone https://gitlab.com/princesspi/general-scripts-and-system-ssssssetup.git /tmp/cscripts'
    become: yes



  - name: "Create directory {{ custom_scripts_dir }}"
    file:
      path: "{{ custom_scripts_dir }}"
      state: directory
      mode: '0755'
      owner: 'root'
      group: 'root'
    become: yes
  - name: 'Customscripts copy add_user_ssh.sh'
    copy:
      remote_src: False
      src: '/tmp/cscripts/customscripts/add_user_ssh.sh'
      dest: "{{ custom_scripts_dir }}/add_user_ssh.sh"
      mode: '0744'
      owner: 'root'
      group: 'root'
    become: yes
  - name: "Customscripts copy crowdsec.sh"
    copy:
      remote_src: False
      src: '/tmp/cscripts/customscripts/crowdsec.sh'
      dest: "{{ custom_scripts_dir }}/crowdsec.sh"
      mode: '0744'
      owner: 'root'
      group: 'root'
    become: yes
  - name: "Customscripts copy fix_permissions.sh"
    copy:
      remote_src: False
      src: '/tmp/cscripts/customscripts/fix_permissions.sh'
      dest: "{{ custom_scripts_dir }}/fix_permissions.sh"
      mode: '0744'
      owner: 'root'
      group: 'root'
    become: yes

# crowdsec
  - name: 'Crowdsec'
    command:
      cmd: "bash {{ custom_scripts_dir }}/crowdsec.sh"
    become: yes

  - name: 'enable/restart crowdsec'
    service:
      name: 'crowdsec'
      enabled: True
      state: 'restarted'
