---

argument_specs:

  main:
    version_added: "0.0.1"
    short_description: Install and configure Mailman 3.
    description:
      - Install and configure the L(Mailman 3,https://docs.mailman3.org/en/latest/) mailing list manager.
      - "Execution of this role can be limited using the following tags:"
      - "C(role::mailman:install): Install Mailman 3 from distribution packages"
      - "C(role::mailman:config): Configure Mailman 3."
      - "C(role::mailman:templates): Override Mailman 3 Django templates."
      - "C(role::mailman:bootstrap): Create mailman3 databases and admin users. Tagged with C(never)."
      - "C(role::mailman:privacy): Create hyperkitty cleanup cronjob."
      - "C(role::knot): Apply all of the above."
    author: s3lph
    options:
      mailman_noreply_address:
        description:
          - >-
            Local-part of an email address used in the From field whenever a message comes from some entity to which
            there is no natural reply recipient.
          - "Mailman will append '@' and the host name of the list involved."
          - "This address must not bounce and it must not point to a Mailman process."
        type: str
        default: noreply
      mailman_default_language:
        description:
          - The default language for this server.
        type: str
        default: en
      mailman_sender_headers:
        description:
          - Membership tests for posting purposes.
          - Headers are checked in the order given in this variable.
          - The value C(From_) means to use the envelope sender.
          - Field names are case insensitive.
        type: list
        elements: str
        default: [from, from_, reply-to,  sender]
      mailman_email_commands_max_lines:
        description:
          - Mail command processor will ignore mail command lines after designated max.
        type: int
        default: 10
      mailman_pending_request_life:
        description:
          - Default length of time a pending request is live before it is evicted from the pending database.
        type: str
        default: 3d
      mailman_cache_life:
        description:
          - How long should files be saved before they are evicted from the cache?
        type: str
        default: 7d
      mailman_pre_hook:
        description:
          - A callable to run with no arguments early in the initialization process.
        type: str
        default: ""
      mailman_post_hook:
        description:
          - A callable to run with no arguments late in the initialization process.
        type: str
        default: ""
      mailman_filtered_messages_are_preservable:
        description:
          - Can MIME filtered messages be preserved by list owners?
        type: str
        default: "no"
      mailman_html_to_plain_text_command:
        description:
          - How should html parts be converted to text/plain when the mailing list is set to convert HTML to plaintext?
          - This names a command to be called, where the substitution variable $filename is filled in by Mailman.
          - The command should print the converted text to stdout.
        type: str
        default: "/usr/bin/lynx -dump $filename"
      mailman_listname_chars:
        description:
          - Specify what characters are allowed in list names.
        type: str
        default: "-_.0-9a-z"

      mailman_shell_prompt:
        description:
          - Customize the interpreter prompt.
        type: str
        default: ">>>"
      mailman_shell_banner:
        description:
          - Banner to show on startup.
        type: str
        default: Welcome to the GNU Mailman shell
      mailman_shell_use_ipython:
        description:
          - Use IPython as the shell, which must be found on the system.
          - Valid values are C(no), C(yes), and C(debug).
        type: str
        default: "no"
      mailman_shell_history_file:
        description:
          - Set this to allow for command line history if readline is available.
        type: str
        default: ""

      mailman_mariadb_user:
        description:
          - Local part of the username for the database connection URI.
          - See O(mailman_database_url).
        type: str
        default: mailman
      mailman_mariadb_user_host:
        description:
          - Host part of the username.
          - This is only used to bootstrap the database user.  There should not be a need to change this.
        type: str
        default: localhost
      mailman_mariadb_password:
        description:
          - Password for the database connection URI.
          - See O(mailman_database_url).
        type: str
        required: true
      mailman_mariadb_host:
        description:
          - Hostname for the database connection URI.
          - See O(mailman_database_url).
        type: str
        default: localhost
      mailman_mariadb_port:
        description:
          - Port for the database connection URI.
          - See O(mailman_database_url).
        type: int
        default: 3306
      mailman_mariadb_database:
        description:
          - Database schema name for the database connection URI.
          - See O(mailman_database_url).
        type: str
        default: mailman

      mailman_database_class:
        description:
          - Class name of the database driver.
          - If the default is changed, O(mailman_database_url) must be provided directly.
        type: str
        default: mailman.database.mysql.MySQLDatabase
      mailman_database_url:
        description:
          - Database connection URI.
          - "If PyMySQL is used, it is recommended to set the following options instead:"
          - O(mailman_mariadb_user)
          - O(mailman_mariadb_password)
          - O(mailman_mariadb_host)
          - O(mailman_mariadb_port)
          - O(mailman_mariadb_database)
        type: str
        default: "mysql+pymysql://{{ mailman_mariadb_user }}:{{ mailman_mariadb_password }}@{{ mailman_mariadb_host }}:{{ mailman_mariadb_port }}/{{ mailman_mariadb_database }}?charset=utf8mb4&use_unicode=1"  # noqa yaml[line-length]
      mailman_database_debug:
        description:
          - Enable debug logging for the database connection.
        type: str
        default: "no"

      mailman_logging_format:
        description:
          - Overrides the default log format string.
        type: str
        default: "%(asctime)s (%(process)d) %(message)s"
      mailman_logging_datefmt:
        description:
          - Overrides the default log date format string.
        type: str
        default: "%b %d %H:%M:%S %Y"
      mailman_logging_propagate:
        description:
          - 'Boolean specifying whether to propagate log message from this logger to the root "mailman" logger.'
        type: str
        default: "no"
      mailman_logging_level:
        description:
          - Overrides the default level.
          - This may be any of the standard Python logging levels, case insensitive.
        type: str
        default: "info"
      mailman_loggging_path:
        description:
          - Overrides the default logger path.
          - "This may be a relative path name, in which case it is relative to Mailman's LOG_DIR."
        type: str
        default: "mailman.log"

      mailman_webservice_hostname:
        description:
          - The hostname at which admin web service resources are exposed.
        type: str
        default: localhost
      mailman_webservice_port:
        description:
          - The port at which the admin web service resources are exposed.
        type: int
        default: 8001
      mailman_webservice_use_https:
        description:
          - Whether or not requests to the web service are secured through SSL.
        type: str
        default: "no"
      mailman_webservice_show_tracebacks:
        description:
          - Whether or not to show tracebacks in an HTTP response for a request that raised an exception.
        type: str
        default: "yes"
      mailman_webservice_api_version:
        description:
          - The API version number for the current (highest) API.
        type: str
        default: "3.1"
      mailman_webservice_admin_user:
        description:
          - The administrative username.
        type: str
        default: restadmin
      mailman_webservice_admin_pass:
        description:
          - The administrative password.
        type: str
        required: true

      mailman_mta_incoming:
        description:
          - The class defining the interface to the incoming mail transport agent.
        type: str
        default: mailman.mta.postfix.LMTP
      mailman_mta_outgoing:
        description:
          - The callable implementing delivery to the outgoing mail transport agent.
        type: str
        default: mailman.mta.deliver.deliver
      mailman_mta_smtp_host:
        description:
          - SMTP host for outgoing MTA.
        type: str
        default: localhost
      mailman_mta_smtp_port:
        description:
          - SMTP port for outgoing MTA.
        type: int
        default: 25
      mailman_mta_smtp_user:
        description:
          - SMTP username for outgoing MTA.
        type: str
        default: ""
      mailman_mta_smtp_pass:
        description:
          - SMTP password for outgoing MTA.
        type: str
        default: ""
      mailman_mta_lmtp_host:
        description:
          - Hostname where the LMTP server listens for connections.
        type: str
        default: 127.0.0.1
      mailman_mta_lmtp_port:
        description:
          - Port where the LMTP server listens for connections.
        type: int
        default: 8024
      mailman_mta_configuration:
        description:
          - Where can we find the mail server specific configuration file?
          - The path can be either a file system path or a Python import path.
        type: str
        default: python:mailman.config.postfix
      mailman_mta_remove_dkim_headers:
        description:
          - If C(true), remove DKIM signatures from incoming messages.
        type: bool
        default: true
      mailman_mta_additional_config:
        description:
          - Wildcard option to append arbitrary additional configuration.
          - Can be used to configure settings not covered by this role.
        type: str
        default: ""

      mailman_hyperkitty_enabled:
        description:
          - If C(true), enable the Hyperkitty mailing list archiver.
          - If C(false), disable the Hyperkitty mailing list archiver.
        type: bool
        default: true
      mailman_hyperkitty_localhost_base_url:
        description:
          - This address will be used by Mailman to forward incoming emails to HyperKitty.
        type: str
        default: http://localhost/hyperkitty/
      mailman_hyperkitty_api_acl:
        description:
          - Hyperkitty will only accept API connections from these hosts.
        type: list
        elements: str
        default: ["127.0.0.1", "::1"]


      mailman_web_secret_key:
        description:
          - "SECURITY WARNING: keep the secret key used in production secret!"
        type: str
        required: true
      mailman_web_admin_name:
        description:
          - Display name of the default mailman-web admin account.
        type: str
        default: Mailman Suite Admin
      mailman_web_admin_email:
        description:
          - Email address of the default mailman-web admin account.
        type: str
        default: root@localhost
      mailman_web_auth_socialaccounts:
        description:
          - List of social login provider plugins to enable.
        type: list
        elements: str
        default: []
      mailman_web_language:
        description:
          - Default language of mailman-web
        type: str
        default: en-us
      mailman_web_timezone:
        description:
          - Default timezone of mailman-web
        type: str
        default: UTC
      mailman_web_emailname:
        description:
          - Default domain for email addresses.
        type: str
        default: "{{ mailman_sitename }}"
      mailman_web_compress_online:
        description:
          - On a production setup, setting COMPRESS_OFFLINE to True will bring a significant performance improvement.
        type: bool
        default: true
      mailman_web_base_url:
        description:
          - Base URL for mailman-web
        type: str
        default: http://localhost/
      mailman_web_static_url:
        description:
          - Path for static content of mailman-web
        type: str
        default: /static/
      mailman_web_disable_gravatar:
        description:
          - If C(true), disable Gravatar integration.
          - If C(false), enable Gravatar integration.
        type: bool
        default: true
      mailman_web_disable_web_posting:
        description:
          - If C(true), disable posting from the Hyperkitty web interface.
          - If C(false), enable web posting.
        type: bool
        default: true
      mailman_web_database_engine:
        description:
          - Django database engine driver to use.
        type: str
        default: django.db.backends.mysql
      mailman_web_database_name:
        description:
          - DB name or path to database file if using sqlite3.
        type: str
        default: 'mailman-web'
      mailman_web_database_host:
        description:
          - Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        type: str
        default: ''
      mailman_web_database_port:
        description:
          - Set to empty string for default of the database driver.
        type: str
        default: ''
      mailman_web_database_user:
        description:
          - Username for the database.
        type: str
        default: 'mailman-web'
      mailman_web_database_password:
        description:
          - Password for the database.
        type: str
        required: true
      mailman_web_database_user_host:
        description:
          - Host part of the username.
          - This is only used to bootstrap the database user.  There should not be a need to change this.
        type: str
        default: 'localhost'
      mailman_web_database_options:
        description:
          - Extra parameters to use when connecting to the database.
        type: dict
        default:
          charset: utf8mb4
          init_command: "SET sql_mode='STRICT_TRANS_TABLES'"
      mailman_web_rest_api_url:
        description:
          - Local mailman-web API endpoint
        type: str
        default: http://localhost:8001
      mailman_web_allowed_hosts:
        description:
          - See U(https://docs.djangoproject.com/en/1.8/ref/settings/#allowed-hosts)
        type: list
        elements: str
        default: ["{{ mailman_sitename }}"]

      mailman_database_postfix_user:
        description:
          - Local part of the database username used by Postfix.
        type: str
        default: mailman-postfix
      mailman_database_postfix_password:
        description:
          - Database password used by Postfix.
        type: str
        required: true
      mailman_database_postfix_user_host:
        description:
          - Host part of the database username used by Postfix.
          - This is only used to bootstrap the database user.  There should not be a need to change this.
        type: str
        default: localhost
      mailman_database_postfix_hosts:
        description:
          - Hostname or socket path of the database used by Postfix.
        type: str
        default: "unix:/run/mysqld/mysqld.sock"

      mailman_mariadb_bootstrap_host:
        description:
          - Database hostname to connect to for initializing the schema and user accounts.
          - Must be provided even if O(mailman_mariadb_bootstrap_socket) is set.
        type: str
        default: ''
      mailman_mariadb_bootstrap_port:
        description:
          - Database port to connect to for initializing the schema and user accounts.
          - Must be provided even if O(mailman_mariadb_bootstrap_socket) is set.
        type: str
        default: 0
      mailman_mariadb_bootstrap_socket:
        description:
          - Database UNIX socket to connect to for initializing the schema and user accounts.
        type: str
        default: /run/mysqld/mysqld.sock
      mailman_mariadb_bootstrap_login_user:
        description:
          - Database admin user to connect with for initializing the schema and user accounts.
        type: str
        default: root
      mailman_mariadb_bootstrap_login_password:
        description:
          - Database admin password to connect with for initializing the schema and user accounts.
          - Not used if UNIX socket authentication is used.
        type: str
        default: ''
      mailman_superuser_name:
        description:
          - Name of the mailman-web Django superuser
        type: str
        default: root
      mailman_superuser_email:
        description:
          - Email address of the mailman-web Django superuser
        type: str
        required: true
      mailman_superuser_password:
        description:
          - Password of the mailman-web Django superuser
        type: str
        required: true

      mailman_web_override_templates:
        description:
          - If C(true), upload some files from the Ansible controller to override mailman-web builtins.
          - Setting this option to C(false) afterwards does NOT remove the overrides.
          - See O(mailman_web_override_templates_path) and O(mailman_web_override_static_path).
        type: bool
        default: false
      mailman_web_override_templates_path:
        description:
          - Directory on the Ansible controller from where to load overridden templates.
        type: str
        default: "{{ playbook_dir }}/templates/override"
      mailman_web_override_static_path:
        description:
          - Directory on the Ansible controller from where to load overridden static files.
        type: str
        default: "{{ playbook_dir }}/static/override"
      mailman_web_hyperkitty_cleanup_cron:
        description:
          - When to run the Hyperkitty cleanup job.
          - See O(mailman_web_privacy_enhancements).
        type: str
        default: '0 * * * *'
      mailman_web_privacy_enhancements:
        description:
          - If C(true), enable a cronjob that removes entries from the access log table of Hyperkitty.
        type: bool
        default: false