- name: Waiting for SSH connection
  ansible.builtin.wait_for_connection:

- name: Gathering facts
  ansible.builtin.setup:

- name: Cloning T-Pot install directory
  ansible.builtin.git:
    repo: "https://github.com/telekom-security/tpotce.git"
    dest: /root/tpot

- name: Prepare to set user password
  ansible.builtin.set_fact:
    user_name: "{{ ansible_user }}"
    user_salt: "s0mew1ck3dTpoT"
  no_log: true

- name: Changing password for user {{ user_name }}
  ansible.builtin.user:
   name: "{{ ansible_user }}"
   password: "{{ user_password | password_hash('sha512', user_salt) }}"
   state: present
   shell: /bin/bash

- name: Copy T-Pot configuration file
  ansible.builtin.copy:
    src: ../../../../../../iso/installer/tpot.conf.dist
    dest: /root/tpot.conf
    owner: root
    group: root
    mode: 0644

- name: Install T-Pot on instance -  be patient, this might take 15 to 30 minutes depending on the connection speed.
  ansible.builtin.command: /root/tpot/iso/installer/install.sh --type=auto --conf=/root/tpot.conf

- name: Delete T-Pot configuration file
  ansible.builtin.file:
    path: /root/tpot.conf
    state: absent

- name: Change unattended-upgrades to take default action
  ansible.builtin.blockinfile:
    dest: /etc/apt/apt.conf.d/50unattended-upgrades
    block: |
      Dpkg::Options {
        "--force-confdef";
        "--force-confold";
      }
