Browse Source

Add FTP-Server playbook

Emmanuel Bouthenot 9 years ago
parent
commit
dd924353bc

+ 4 - 0
ftpserver.yml

@@ -0,0 +1,4 @@
+- hosts: ftpserver
+  roles:
+    - ftpserver
+

+ 8 - 0
roles/ftpserver/defaults/main.yml

@@ -0,0 +1,8 @@
+#
+# Default variables for webservers
+#
+
+with_ftp: False
+ftp_accounts: Null
+
+# vim: ft=yaml

+ 1 - 0
roles/ftpserver/handlers/main.yml

@@ -0,0 +1 @@
+- include: pure-ftpd.yml

+ 2 - 0
roles/ftpserver/handlers/pure-ftpd.yml

@@ -0,0 +1,2 @@
+- name: Restart pure-ftpd
+  service: name=pure-ftpd state=restarted

+ 1 - 0
roles/ftpserver/tasks/main.yml

@@ -0,0 +1 @@
+- include: pure-ftpd.yml

+ 46 - 0
roles/ftpserver/tasks/pure-ftpd.yml

@@ -0,0 +1,46 @@
+- name: Install pure-ftpd related packages
+  apt: pkg={{ item }} state=installed update_cache=yes
+  with_items:
+    - pure-ftpd
+  when: with_ftp
+
+- name: Install pure-ftpd configuration
+  lineinfile:
+    dest: '/etc/pure-ftpd/conf/{{ item.dest }}'
+    regexp: '{{ item.regexp }}'
+    line: '{{ item.line }}'
+    create: yes
+  with_items:
+    - { dest: 'BrokenClientsCompatibility', regexp: '^(yes|no)', line: 'yes' }
+    - { dest: 'ChrootEveryone', regexp: '^(yes|no)', line: 'yes' }
+    - { dest: 'DontResolve', regexp: '^(yes|no)', line: 'yes' }
+    - { dest: 'NoAnonymous', regexp: '^(yes|no)', line: 'yes' }
+    - { dest: 'NoChmod', regexp: '^(yes|no)', line: 'yes' }
+    - { dest: 'PAMAuthentication', regexp: '^(yes|no)', line: 'yes' }
+    - { dest: 'VerboseLog', regexp: '^(yes|no)', line: 'no' }
+  notify:
+    - Restart pure-ftpd
+  when: with_ftp
+
+- name: Enable pure-ftpd internal DB
+  file: src=/etc/pure-ftpd/conf/PureDB path=/etc/pure-ftpd/auth/80puredb state=link
+  notify:
+    - Restart pure-ftpd
+  when: with_ftp
+
+- name: Clean up pure-ftpd internal DB
+  raw: pure-pw list 2>/dev/null | sed -r 's/^(\S+)\s.*$/\1/' | while read u ; do pure-pw userdel "${u}" ; done
+  when: with_ftp
+
+- name: Add FTP accounts in pure-ftpd
+  raw: printf "{{item.password}}\n{{item.password}}\n" | pure-pw useradd "{{item.user}}" -d "{{item.home}}" -u "{{item.uid}}" -g "{{item.gid}}"
+  with_items: ftp_accounts
+  when: ftp_accounts and with_ftp
+
+- name: Rebuild pure-ftpd internal DB
+  raw: pure-pw mkdb 2>/dev/null
+  when: with_ftp
+
+- name: Ensure pure-ftpd is running
+  service: name=pure-ftpd state=started
+  when: with_ftp

+ 1 - 0
site.yml

@@ -2,4 +2,5 @@
 - include: hypervisor.yml
 - include: webserver.yml
 - include: dbserver.yml
+- include: ftpserver.yml
 - include: monitoring.yml