2017-06-28 14:12:04 +02:00
|
|
|
---
|
|
|
|
- name: Check if FTP account exist
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: grep "^{{ proftpd_name }}:" /etc/proftpd/vpasswd
|
2023-03-16 14:35:12 +01:00
|
|
|
failed_when: False
|
2017-06-28 14:12:04 +02:00
|
|
|
check_mode: no
|
|
|
|
changed_when: check_ftp_account.rc != 0
|
|
|
|
register: check_ftp_account
|
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|
2017-06-28 14:12:04 +02:00
|
|
|
|
|
|
|
- name: Generate FTP password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.command:
|
|
|
|
cmd: apg -n1
|
2017-06-28 14:12:04 +02:00
|
|
|
register: ftp_password
|
|
|
|
check_mode: no
|
|
|
|
when: check_ftp_account.rc != 0
|
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|
2017-06-28 14:12:04 +02:00
|
|
|
|
|
|
|
- name: Print generated password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.debug:
|
2017-06-28 14:12:04 +02:00
|
|
|
msg: "{{ ftp_password.stdout }}"
|
|
|
|
when: check_ftp_account.rc != 0
|
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|
2017-06-28 14:12:04 +02:00
|
|
|
|
|
|
|
- name: Hash generated FTP password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.set_fact:
|
2017-06-28 14:12:04 +02:00
|
|
|
proftpd_password: "{{ ftp_password.stdout | password_hash('sha512') }}"
|
|
|
|
check_mode: no
|
|
|
|
when: check_ftp_account.rc != 0
|
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|
2017-06-28 14:12:04 +02:00
|
|
|
|
|
|
|
- name: Get current FTP password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.shell:
|
|
|
|
cmd: grep "^{{ proftpd_name }}:" /etc/proftpd/vpasswd | cut -d':' -f2
|
2017-06-28 14:12:04 +02:00
|
|
|
register: hashed_ftp_password
|
|
|
|
check_mode: no
|
|
|
|
when: check_ftp_account.rc == 0
|
2023-03-16 14:35:12 +01:00
|
|
|
changed_when: False
|
2017-06-28 14:12:04 +02:00
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|
2017-06-28 14:12:04 +02:00
|
|
|
|
|
|
|
- name: Get current FTP password
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.set_fact:
|
2017-06-28 14:12:04 +02:00
|
|
|
proftpd_password: "{{ hashed_ftp_password.stdout }}"
|
|
|
|
check_mode: no
|
|
|
|
when: check_ftp_account.rc == 0
|
2023-03-16 14:35:12 +01:00
|
|
|
changed_when: False
|
2017-06-28 14:12:04 +02:00
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|
2017-06-28 14:12:04 +02:00
|
|
|
|
|
|
|
- name: Create FTP account
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2017-06-28 14:12:04 +02:00
|
|
|
dest: /etc/proftpd/vpasswd
|
|
|
|
state: present
|
|
|
|
create: yes
|
|
|
|
mode: "0440"
|
|
|
|
line: "{{ proftpd_name }}:{{ proftpd_password }}:{{ proftpd_uid }}:{{ proftpd_gid }}::{{ proftpd_home }}:/bin/false"
|
|
|
|
notify: restart proftpd
|
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|
2017-06-28 14:12:04 +02:00
|
|
|
|
|
|
|
- name: Allow FTP account
|
2023-03-20 23:33:19 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2017-06-28 14:12:04 +02:00
|
|
|
dest: /etc/proftpd/conf.d/z-evolinux.conf
|
|
|
|
state: present
|
|
|
|
line: " AllowUser {{ proftpd_name }}"
|
2018-04-04 23:21:31 +02:00
|
|
|
insertbefore: "DenyAll"
|
2017-06-28 14:12:04 +02:00
|
|
|
notify: restart proftpd
|
|
|
|
tags:
|
2017-12-04 13:50:21 +01:00
|
|
|
- proftpd
|