diff --git a/defaults/main.yml b/defaults/main.yml index 1b1dc33..41d679a 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -32,6 +32,20 @@ nexus_anonymous_access: false public_hostname: 'nexus.vm' +# email server +nexus_email_server_enabled: false +nexus_email_server_host: "localhost" +nexus_email_server_port: 25 +nexus_email_server_username: "" +nexus_email_server_password: "" +nexus_email_from_address: "nexus@example.org" +nexus_email_subject_prefix: "" +nexus_email_tls_enabled: false +nexus_email_tls_required: false +nexus_email_ssl_on_connect_enabled: false +nexus_email_ssl_check_server_identity_enabled: false +nexus_email_trust_store_enabled: false + nexus_branding_header: "" nexus_branding_footer: "Last provisionned {{ ansible_date_time.iso8601 }}" @@ -158,6 +172,7 @@ nexus_scheduled_tasks: - name: db-backup # Note: CRON must be aligned to nexus-blob-backup.sh cron schedule. -> Task: "Config nexus-backup shell cron" cron: '0 0 21 * * ?' typeId: db.backup + task_alert_email: alerts@example.org # optional taskProperties: location: "{{ nexus_backup_dir }}/" @@ -166,6 +181,7 @@ nexus_scheduled_tasks: # - name: compact-blobstore # cron: '0 0 22 * * ?' # typeId: blobstore.compact +# task_alert_email: alerts@example.org # optional # taskProperties: # blobstoreName: 'default' # all task attributes are stored as strings by nexus internally diff --git a/files/groovy/create_task.groovy b/files/groovy/create_task.groovy index 22fc37e..0f1f6bf 100644 --- a/files/groovy/create_task.groovy +++ b/files/groovy/create_task.groovy @@ -21,6 +21,10 @@ taskConfiguration.setName(parsed_args.name) parsed_args.taskProperties.each { key, value -> taskConfiguration.setString(key, value) } +if (parsed_args.task_alert_email) { + taskConfiguration.setAlertEmail(parsed_args.task_alert_email) +} + Schedule schedule = taskScheduler.scheduleFactory.cron(new Date(), parsed_args.cron) -taskScheduler.scheduleTask(taskConfiguration, schedule) \ No newline at end of file +taskScheduler.scheduleTask(taskConfiguration, schedule) diff --git a/files/groovy/setup_email.groovy b/files/groovy/setup_email.groovy new file mode 100644 index 0000000..9c0e738 --- /dev/null +++ b/files/groovy/setup_email.groovy @@ -0,0 +1,24 @@ +import groovy.json.JsonSlurper +import org.sonatype.nexus.email.EmailConfiguration +import org.sonatype.nexus.email.EmailManager + +parsed_args = new JsonSlurper().parseText(args) + +def emailMgr = container.lookup(EmailManager.class.getName()); + +emailConfig = new EmailConfiguration( + enabled: parsed_args.email_server_enabled, + host: parsed_args.email_server_host, + port: Integer.valueOf(parsed_args.email_server_port), + username: parsed_args.email_server_username, + password: parsed_args.email_server_password, + fromAddress: parsed_args.email_from_address, + subjectPrefix: parsed_args.email_subject_prefix, + startTlsEnabled: parsed_args.email_tls_enabled, + startTlsRequired: parsed_args.email_tls_required, + sslOnConnectEnabled: parsed_args.email_ssl_on_connect_enabled, + sslCheckServerIdentityEnabled: parsed_args.email_ssl_check_server_identity_enabled, + nexusTrustStoreEnabled: parsed_args.email_trust_store_enabled +) + +emailMgr.configuration = emailConfig diff --git a/tasks/main.yml b/tasks/main.yml index 506c4ba..ca8ebc5 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -150,6 +150,23 @@ args: base_url: "https://{{ public_hostname }}/" +- include: call_script.yml + vars: + script_name: setup_email + args: + email_server_enabled: "{{ nexus_email_server_enabled }}" + email_server_host: "{{ nexus_email_server_host }}" + email_server_port: "{{ nexus_email_server_port }}" + email_server_username: "{{ nexus_email_server_username }}" + email_server_password: "{{ nexus_email_server_password }}" + email_from_address: "{{ nexus_email_from_address }}" + email_subject_prefix: "{{ nexus_email_subject_prefix }}" + email_tls_enabled: "{{ nexus_email_tls_enabled }}" + email_tls_required: "{{ nexus_email_tls_required }}" + email_ssl_on_connect_enabled: "{{ nexus_email_ssl_on_connect_enabled }}" + email_ssl_check_server_identity_enabled: "{{ nexus_email_ssl_check_server_identity_enabled }}" + email_trust_store_enabled: "{{ nexus_email_trust_store_enabled }}" + - name: Configure branding capability include: call_script.yml vars: diff --git a/tasks/nexus_install.yml b/tasks/nexus_install.yml index 42b6a58..9190c17 100644 --- a/tasks/nexus_install.yml +++ b/tasks/nexus_install.yml @@ -257,6 +257,7 @@ - setup_role - setup_privilege - setup_user + - setup_email - delete_repo - delete_blobstore - create_blobstore