- name: Install packages.
  apt:
    name: [ "proftpd-basic" ]

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

- name: Create FTP users.
  debug:
    msg: "echo {{ eci_passwords[item] }}|ftpasswd --passwd --file=/etc/proftpd/ftpd.passwd --name={{item}} --uid={{eci_users_uid[item]}} --home=/udirs/{{item}} --shell=/bin/false --stdin"
  loop: "{{eci_users}}"
  notify: restart-ftp

    
- name: Configure ProFTPd for multiple virtual users.
  blockinfile:
    path: /etc/proftpd/proftpd.conf
    block: |
      DefaultRoot ~
      RequireValidShell off
      AuthUserFile /etc/proftpd/ftpd.passwd
      AuthGroupFile /etc/proftpd/ftpd.group
      ServerName "{{hostvars[inventory_hostname].ansible_hostname}}"
      AuthOrder mod_auth_file.c
  notify: restart-ftp