diff --git a/README.md b/README.md index 3637db8..4dea0f7 100644 --- a/README.md +++ b/README.md @@ -1,31 +1,49 @@ Role Name ========= -A brief description of the role goes here. - -Requirements ------------- - -Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. +A role that installs vstpd, Role Variables -------------- -A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. +The most important variables are listed below: + +``` yaml +vsftpd_server_enabled: True +vsftpd_anonymous_enable: "NO" +vsftpd_local_enable: "YES" +vsftpd_write_enable: "YES" +vsftpd_local_umask: "077" +vsftpd_dirmessage_enable: "YES" +vsftpd_connect_from_port_20: "YES" +vsftpd_ls_recurse_enable: "NO" +vsftpd_local_root: /dev/null +vsftpd_pasv_min_port: 49152 +vsftpd_pasv_max_port: 65534 +vsftpd_chroot_list_enable: "YES" +vsftpd_chroot_list_file: /etc/vsftpd.chroot_list +vsftpd_chroot_passwd_enable: "NO" +vsftpd_chroot_local_user: "NO" +vsftpd_iptables_rules: True +vsftpd_iptables_allowed_hosts: + - 0.0.0.0/0 + +vsftpd_manage_user_acls: True +vsftpd_manage_real_users: False +vsftpd_manage_valid_shells: False + +vsftpd_tls_enabled: True +vsftpd_force_tls: True +vsftpd_tls_letsencrypt: True +vsftpd_ssl_ca_certificate: '{{ letsencrypt_acme_certs_dir }}/fullchain' +vsftpd_ssl_certificate: '{{ letsencrypt_acme_certs_dir }}/cert' +vsftpd_ssl_certificate_key: '{{ letsencrypt_acme_certs_dir }}/privkey' +``` Dependencies ------------ -A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. - -Example Playbook ----------------- - -Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: - - - hosts: servers - roles: - - { role: username.rolename, x: 42 } +None License ------- @@ -35,4 +53,4 @@ EUPL-1.2 Author Information ------------------ -An optional section for the role authors to include contact information, or a website (HTML is not allowed). +Andrea Dell'Amico, diff --git a/defaults/main.yml b/defaults/main.yml index 95d3c70..61b09f1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,31 @@ --- -# defaults file for ansible-role-template \ No newline at end of file +vsftpd_server_enabled: True +vsftpd_anonymous_enable: "NO" +vsftpd_local_enable: "YES" +vsftpd_write_enable: "YES" +vsftpd_local_umask: "077" +vsftpd_dirmessage_enable: "YES" +vsftpd_connect_from_port_20: "YES" +vsftpd_ls_recurse_enable: "NO" +vsftpd_local_root: /dev/null +vsftpd_pasv_min_port: 49152 +vsftpd_pasv_max_port: 65534 +vsftpd_chroot_list_enable: "YES" +vsftpd_chroot_list_file: /etc/vsftpd.chroot_list +vsftpd_chroot_passwd_enable: "NO" +vsftpd_chroot_local_user: "NO" +vsftpd_iptables_rules: True +vsftpd_iptables_allowed_hosts: + - 0.0.0.0/0 + +vsftpd_manage_user_acls: True +vsftpd_manage_real_users: False +vsftpd_manage_valid_shells: False + +vsftpd_tls_enabled: True +vsftpd_force_tls: True +vsftpd_tls_letsencrypt: True +vsftpd_ssl_ca_certificate: '{{ letsencrypt_acme_certs_dir }}/fullchain' +vsftpd_ssl_certificate: '{{ letsencrypt_acme_certs_dir }}/cert' +vsftpd_ssl_certificate_key: '{{ letsencrypt_acme_certs_dir }}/privkey' + diff --git a/handlers/main.yml b/handlers/main.yml index 27474e0..a1a0e32 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,2 +1,9 @@ --- -# handlers file for ansible-role-template \ No newline at end of file +- name: Stop the vsftpd server + service: name=vsftpd state=stopped + +- name: Restart the vsftpd server + service: name=vsftpd state=restarted + +- name: Reload the vsftpd server + service: name=vsftpd state=reloaded diff --git a/meta/main.yml b/meta/main.yml index 1126a5e..b3fe494 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -1,61 +1,26 @@ galaxy_info: - author: your name - description: your description + author: Andrea Dell'Amico + description: Systems Architect company: ISTI-CNR - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value issue_tracker_url: https://redmine-s2i2s.isti.cnr.it/projects/provisioning - # Some suggested licenses: - # - BSD (default) - # - MIT - # - GPLv2 - # - GPLv3 - # - Apache - # - CC-BY - license: EUPL-1.2 + license: EUPL 1.2+ min_ansible_version: 2.8 - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: - - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - #github_branch: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. # To view available platforms and versions (or releases), visit: # https://galaxy.ansible.com/api/v1/platforms/ # - # platforms: - # - name: Fedora - # versions: - # - all - # - 25 - # - name: SomePlatform - # versions: - # - all - # - 1.0 - # - 7 - # - 99.99 + platforms: + - name: Ubuntu + versions: + - bionic - galaxy_tags: [] - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. + galaxy_tags: + - ftp + - ftpd + - vsftp + - vsftpd dependencies: [] - # List your role dependencies here, one per line. Be sure to remove the '[]' above, - # if you add dependencies to this list. - diff --git a/tasks/main.yml b/tasks/main.yml index 53c6cae..0885c9c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,21 @@ --- -# tasks file for ansible-role-template \ No newline at end of file +- name: Install the vsftpd package + apt: pkg=vsftpd state=present update_cache=yes cache_valid_time=3600 + tags: [ 'vsftpd', 'ftp' ] + +- name: Install the vsftpd configuration file + template: src=vsftpd.conf.j2 dest=/etc/vsftpd.conf mode=0444 owner=root group=root + notify: Restart the vsftpd server + tags: [ 'vsftpd', 'ftp' ] + +- name: Start and enable the vsftpd server + service: name=vsftpd state=started enabled=yes + when: vsftpd_server_enabled + tags: [ 'vsftpd', 'ftp' ] + +- name: Stop and disable the vsftpd server + service: name=vsftpd state=stopped + when: not vsftpd_server_enabled + tags: [ 'vsftpd', 'ftp' ] + + diff --git a/templates/vsftpd.conf.j2 b/templates/vsftpd.conf.j2 new file mode 100644 index 0000000..a2eeeea --- /dev/null +++ b/templates/vsftpd.conf.j2 @@ -0,0 +1,152 @@ +# +# Run standalone? vsftpd can run either from an inetd or as a standalone +# daemon started from an initscript. +listen=YES +# +# Run standalone with IPv6? +# Like the listen parameter, except vsftpd will listen on an IPv6 socket +# instead of an IPv4 one. This parameter and the listen parameter are mutually +# exclusive. +#listen_ipv6=YES +# +# Allow anonymous FTP? (Beware - allowed by default if you comment this out). +anonymous_enable={{ vsftpd_anonymous_enable }} +# +# Uncomment this to allow local users to log in. +local_enable={{ vsftpd_local_enable }} +# +# Uncomment this to enable any form of FTP write command. +write_enable={{ vsftpd_write_enable }} +# +# Default umask for local users is 077. You may wish to change this to 022, +# if your users expect that (022 is used by most other ftpd's) +local_umask={{ vsftpd_local_umask }} +# +# Uncomment this to allow the anonymous FTP user to upload files. This only +# has an effect if the above global write enable is activated. Also, you will +# obviously need to create a directory writable by the FTP user. +#anon_upload_enable=YES +# +# Uncomment this if you want the anonymous FTP user to be able to create +# new directories. +#anon_mkdir_write_enable=YES +# +# Activate directory messages - messages given to remote users when they +# go into a certain directory. +dirmessage_enable={{ vsftpd_dirmessage_enable }} +# +# If enabled, vsftpd will display directory listings with the time +# in your local time zone. The default is to display GMT. The +# times returned by the MDTM FTP command are also affected by this +# option. +use_localtime=YES +# +# Activate logging of uploads/downloads. +xferlog_enable=YES +# +# Make sure PORT transfer connections originate from port 20 (ftp-data). +connect_from_port_20={{ vsftpd_connect_from_port_20 }} +# +# If you want, you can arrange for uploaded anonymous files to be owned by +# a different user. Note! Using "root" for uploaded files is not +# recommended! +#chown_uploads=YES +#chown_username=whoever +# +# You may override where the log file goes if you like. The default is shown +# below. +#xferlog_file=/var/log/vsftpd.log +# +# If you want, you can have your log file in standard ftpd xferlog format. +# Note that the default log file location is /var/log/xferlog in this case. +#xferlog_std_format=YES +# +# You may change the default value for timing out an idle session. +#idle_session_timeout=600 +# +# You may change the default value for timing out a data connection. +#data_connection_timeout=120 +# +# It is recommended that you define on your system a unique user which the +# ftp server can use as a totally isolated and unprivileged user. +#nopriv_user=ftpsecure +# +# Enable this and the server will recognise asynchronous ABOR requests. Not +# recommended for security (the code is non-trivial). Not enabling it, +# however, may confuse older FTP clients. +#async_abor_enable=YES +# +# By default the server will pretend to allow ASCII mode but in fact ignore +# the request. Turn on the below options to have the server actually do ASCII +# mangling on files when in ASCII mode. +# Beware that on some FTP servers, ASCII support allows a denial of service +# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd +# predicted this attack and has always been safe, reporting the size of the +# raw file. +# ASCII mangling is a horrible feature of the protocol. +#ascii_upload_enable=YES +#ascii_download_enable=YES +# +# You may fully customise the login banner string: +#ftpd_banner=Welcome to blah FTP service. +# +# You may specify a file of disallowed anonymous e-mail addresses. Apparently +# useful for combatting certain DoS attacks. +#deny_email_enable=YES +# (default follows) +#banned_email_file=/etc/vsftpd.banned_emails +# + +# You may activate the "-R" option to the builtin ls. This is disabled by +# default to avoid remote users being able to cause excessive I/O on large +# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume +# the presence of the "-R" option, so there is a strong case for enabling it. +ls_recurse_enable={{ vsftpd_ls_recurse_enable }} +# +# Customization +# +# Some of vsftpd's settings don't fit the filesystem layout by +# default. +# +# This option should be the name of a directory which is empty. Also, the +# directory should not be writable by the ftp user. This directory is used +# as a secure chroot() jail at times vsftpd does not require filesystem +# access. +secure_chroot_dir=/var/run/vsftpd/empty +# +# This string is the name of the PAM service vsftpd will use. +pam_service_name=vsftpd +# +{% if vsftpd_tls_enabled %} +# SSL/TLS +ssl_enable=YES +ssl_sslv2=NO +ssl_sslv3=NO +{% if ansible_distribution_version is version_compare('18.04', '>=') %} +ssl_tlsv1=NO +ssl_tlsv1_1=NO +ssl_tlsv1_2=YES +{% else %} +ssl_tlsv1=YES +{% endif %} +ca_certs_file={{ vsftpd_ssl_ca_certificate }} +rsa_cert_file={{ vsftpd_ssl_certificate }} +rsa_private_key_file={{ vsftpd_ssl_certificate_key }} +{% if vsftpd_force_tls %} +force_local_logins_ssl=YES +force_local_data_ssl=YES +{% endif %} +{% else %} +# This option specifies the location of the RSA certificate to use for SSL +# encrypted connections. +rsa_cert_file=/etc/ssl/private/vsftpd.pem +{% endif %} + +local_root={{ vsftpd_local_root }} +pasv_min_port={{ vsftpd_pasv_min_port }} +pasv_max_port={{ vsftpd_pasv_max_port }} +chroot_list_enable={{ vsftpd_chroot_list_enable }} +chroot_list_file={{ vsftpd_chroot_list_file }} +passwd_chroot_enable={{ vsftpd_chroot_passwd_enable }} +chroot_local_user={{ vsftpd_chroot_local_user }} +