---
- name: install proftpd
  apt:
    name: proftpd
    state: present
    update_cache: yes

- name: enable proftpd
  service:
    name: proftpd
    state: started

- name: copy over config files
  copy:
    src: "{{ role_path }}/templates/{{ item.src }}"
    dest: "/etc/proftpd/{{ item.dest }}"
    owner: root
    group: root
    mode: "{{ item.mode }}"
  loop:
    - { src: blacklist.dat, dest: blacklist.dat, mode: "644" }
    - { src: ldap.conf, dest: ldap.conf, mode: "600" }
    - { src: modules.conf, dest: modules.conf, mode: "644" }
    - { src: proftpd.conf, dest: proftpd.conf, mode: "644" }
    - { src: sql.conf, dest: sql.conf, mode: "600" }
    - { src: tls.conf, dest: tls.conf, mode: "644" }
    - { src: virtuals.conf, dest: virtuals.conf, mode: "644" }

- name: create dhparams.pem
  # will not regenerated every playbook run
  command:
    cmd: >
      openssl dhparam 
      -outform PEM -2|-5 
      1024|1536|2048|3072|4096|6144|7680|8192 
      >> /etc/proftpd/dhparams.pem
    creates: /etc/proftpd/dhparams.pem

- name: restart and enable proftpd
  service:
    name: proftpd
    state: restarted
    enabled: yes