- name: Install packages.
  apt:
    name: [ "proftpd-core",
            "proftpd-mod-crypto",
            "proftpd-mod-wrap" ]

- name: Ensure group auth exists.
  file:
    state: touch
    path: /etc/proftpd/ftpd.group
    mode: 0600

- name: Create FTP users.
  shell:
    cmd: "echo {{ eci_passwords[item] }}|ftpasswd --passwd --file=/etc/proftpd/ftpd.passwd --name={{ item }} --uid={{ eci_users_uid[item] }} --gid={{ ansible_facts.getent_group['eci'][1] }} --home=/eci-users/{{item}} --shell=/bin/false --stdin"
  loop: "{{eci_users}}"
  notify: restart-ftp

- name: Copy proftpd config.
  notify: restart-ftp
  ansible.builtin.copy:
    src: files/etc/proftpd/
    dest: /etc/proftpd

- name: FTP Server name.
  ansible.builtin.lineinfile:
    regexp: '^ServerName'
    line: "ServerName \"{{ hostvars[inventory_hostname].ansible_hostname }}\""
    path: /etc/proftpd/proftpd.conf
  notify: restart-ftp