Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding email server configuration task #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]"
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 }}"

Expand Down Expand Up @@ -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: [email protected] # optional
taskProperties:
location: "{{ nexus_backup_dir }}/"

Expand All @@ -166,6 +181,7 @@ nexus_scheduled_tasks:
# - name: compact-blobstore
# cron: '0 0 22 * * ?'
# typeId: blobstore.compact
# task_alert_email: [email protected] # optional
# taskProperties:
# blobstoreName: 'default' # all task attributes are stored as strings by nexus internally

Expand Down
6 changes: 5 additions & 1 deletion files/groovy/create_task.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
taskScheduler.scheduleTask(taskConfiguration, schedule)
24 changes: 24 additions & 0 deletions files/groovy/setup_email.groovy
Original file line number Diff line number Diff line change
@@ -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
17 changes: 17 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tasks/nexus_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
- setup_role
- setup_privilege
- setup_user
- setup_email
- delete_repo
- delete_blobstore
- create_blobstore
Expand Down