ProHoster > Blog > Administration > Installing and configuring Nexus Sonatype using the infrastructure as code approach
Installing and configuring Nexus Sonatype using the infrastructure as code approach
Sonatype Nexus is an integrated platform that allows developers to proxy, store, and manage Java (Maven) dependencies, Docker, Python, Ruby, NPM, Bower, RPM packages, gitlfs, Apt, Go, Nuget, and distribute their software security.
Why do you need Sonatype Nexus?
To store private artifacts;
For caching artifacts that are downloaded from the Internet;
Artifacts supported in the base distribution of Sonatype Nexus:
Variables with default values ββ(see default/main.yml):
General variables
nexus_version: ''
nexus_timezone: 'UTC'
By default, the role will install the latest version of Nexus available. You can fix the version by changing the variable nexus_version. See available versions at https://www.sonatype.com/download-oss-sonatype.
If you change to a newer version, the role will attempt to update your installed Nexus.
If you are using an older version of Nexus than the latest, you must ensure that you are not using features that are not available in the installed release (e.g. hosting yum repositories available for nexus greater than 3.8.0, git lfs repo for nexus greater than 3.3.0 etc.)
nexus timezone is the Java time zone name, which can be useful in combination with the following cron expressions for nexus_scheduled tasks.
The port and context path of the Java connection process. nexus_default_context_path must contain a slash when set, e.g.: nexus_default_context_path: '/nexus/'.
Nexus OS user and group
nexus_os_group: 'nexus'
nexus_os_user: 'nexus'
The user and group used to own the Nexus files and run the service will be created by the role, if not present.
nexus_os_user_home_dir: '/home/nexus'
Allow changing default home directory for nexus user
nexus_data_dir contains all configuration, repositories and downloaded artifacts. Custom blobstore paths nexus_data_dir can be customized, see below nexus_blobstores.
nexus_tmp_dir contains all temporary files. The default path for redhat has been moved from /tmp to overcome potential problems with automatic cleaning procedures. See #168.
These are the default settings for the Nexus. Please do not change these values.If you haven't read nexus system requirements memory section and don't know what they're doing.
As a second warning, here is an excerpt from the above document:
It is not recommended to increase the JVM heap beyond the recommended values ββin an attempt to improve performance. It can actually have the opposite effect, causing the operating system to run unnecessarily.
Administrator password
nexus_admin_password: 'changeme'
Account password "admin" for configuration. This only works on first install by default. Please see [Change admin password after first install](# change-admin-password-after-first-install) if you want to change it later with a role.
It is highly recommended not to store your password in cleartext in the playbook, but to use [ansible-vault encryption] (https://docs.ansible.com/ansible/latest/user_guide/vault.html) (either built-in or in a separate file loaded, for example, using include_vars)
Anonymous access by default
nexus_anonymous_access: false
Anonymous access is disabled by default. More about anonymous access.
These variables control how the role connects to the Nexus API for provisioning. For advanced users only. Chances are you don't want to change these default settings.
Set SSL Reverse Proxy.
To do this, you need to install httpd. Note: when for httpd_setup_enable set valuetrue, nexus binds to 127.0.0.1:8081, so not being directly accessible on HTTP port 8081 from an external IP address.
The default hostname to use is nexus_public_hostname. If you need different names for whatever reason, you can set httpd_server_name with a different meaning.
Π‘ httpd_copy_ssl_files: true (default) The above certificates must exist in your playbook directory and will be copied to the server and configured in apache.
If you want to use existing certificates on the server, install httpd_copy_ssl_files: false and provide the following variables:
# These specifies to the vhost where to find on the remote server file
# system the certificate files.
httpd_ssl_cert_file_location: "/etc/pki/tls/certs/wildcard.vm.crt"
httpd_ssl_cert_key_location: "/etc/pki/tls/private/wildcard.vm.key"
# httpd_ssl_cert_chain_file_location: "{{ httpd_ssl_cert_file_location }}"
httpd_ssl_cert_chain_file_location is optional and should be left unset if you don't want to customize the chain file
nexus_privileges:
- name: all-repos-read # used as key to update a privilege
# type: <one of application, repository-admin, repository-content-selector, repository-view, script or wildcard>
description: 'Read & Browse access to all repos'
repository: '*'
actions: # can be add, browse, create, delete, edit, read or * (all)
- read
- browse
# pattern: pattern
# domain: domain
# script_name: name
List privileges for settings. Look at the documentation and GUI to check which variables should be set depending on the privilege type.
These elements are merged with the following defaults:
nexus_roles:
- id: Developpers # can map to a LDAP group id, also used as a key to update a role
name: developers
description: All developers
privileges:
- nx-search-read
- all-repos-read
roles: [] # references to other role names
nexus_local_users: []
# - username: jenkins # used as key to update
# state: present # default value if ommited, use 'absent' to remove user
# first_name: Jenkins
# last_name: CI
# email: [email protected]
# password: "s3cr3t"
# roles:
# - developers # role ID
Local (non-LDAP) users/accounts list to create in nexus.
List of local (non-LDAP) users/accounts to create on Nexus.
Mapping Ldap users/roles. State absent will remove roles from an existing user if it already exists.
Ldap users are not deleted. Attempting to set a role for a non-existent user will result in an error.
Content selectors
nexus_content_selectors:
- name: docker-login
description: Selector for docker login privilege
search_expression: format=="docker" and path=~"/v2/"
For more information about the content selector, see Documentation.
To use the content selector, add a new privilege with type: repository-content-selector and relevantcontentSelector
Delete the repositories from the nexus install initial default configuration. This step is only executed on first-time install (when nexus_data_dir has been detected empty).
Removing repositories from the original Nexus default configuration. This step is only performed during the first installation (when nexus_data_dir empty).
nexus_delete_default_blobstore: false
Delete the default blobstore from the nexus install initial default configuration. This can only be done if nexus_delete_default_repos: true and all configured repositories (see below) have an explicit blob_store: custom. This step is only executed on first-time install (when nexus_data_dir has been detected empty).
Deleting blob storage (binary artifacts) is disabled by default from the initial configuration. To remove blob storage (binary artifacts), turn off nexus_delete_default_repos: true. This step is only performed during the first installation (when nexus_data_dir empty).
Blobstores to create. A blobstore path and a repository blobstore cannot be updated after initial creation (any update here will be ignored on re-provisionning).
Configuring blobstore on S3 is provided as a convenience and is not part of the automated tests we run on travis. Please note that storing on S3 is only recommended for instances deployed on AWS.
Creation Blobstores. The repository path and repository repository cannot be updated after initial creation (any update here will be ignored on reinstallation).
Setting up blob storage on S3 is provided as a convenience. Please note that S3 storage is only recommended for instances deployed on AWS.
nexus_repos_maven_hosted:
- name: private-release
version_policy: release
write_policy: allow_once # one of "allow", "allow_once" or "deny"
Maven hosted repositories configuration. Negative cache config is optionnal and will default to the above values ββif omitted.
Configuration hosted repositories Maven. The negative cache configuration (-1) is optional and will default to the above values ββif not specified.
nexus_repos_maven_group:
- name: public
member_repos:
- central
- jboss
All three repository types are combined with the following defaults:
_nexus_repos_maven_defaults:
blob_store: default # Note : cannot be updated once the repo has been created
strict_content_validation: true
version_policy: release # release, snapshot or mixed
layout_policy: strict # strict or permissive
write_policy: allow_once # one of "allow", "allow_once" or "deny"
maximum_component_age: -1 # Nexus gui default. For proxies only
maximum_metadata_age: 1440 # Nexus gui default. For proxies only
negative_cache_enabled: true # Nexus gui default. For proxies only
negative_cache_ttl: 1440 # Nexus gui default. For proxies only
Docker, Pypi, Raw, Rubygems, Bower, NPM, Git-LFS and yum repository types:
see defaults/main.yml for these options:
Docker, Pypi, Raw, Rubygems, Bower, NPM, Git-LFS and yum repositories are disabled by default:
See defaults/main.yml for these options:
The backup will not be configured until you switch nexus_backup_configure Π² true.
In this case, the script scheduled task will be configured to run on the Nexus
at the interval specified in nexus_backup_cron (default 21:00 every day).
See the [groovy template for this task](templates / backup.groovy.j2) for details.
This scheduled task is independent of others nexus_scheduled_taskswhich you
announce in your playbook.
If you want to rotate/delete backups, install nexus_backup_rotate: true and set the number of backups you would like to keep with nexus_backup_keep_rotations (default 4).
When using rotation, if you want to save extra disk space during the backup process,
You can install nexus_backup_rotate_first: true. This will set up pre-rotation/removal before backup. By default, rotation occurs after the backup is created. Note than in this case old backups
will be deleted before the current backup is made.
Recovery procedure
Run playbook with parameter -e nexus_restore_point=<YYYY-MM-dd-HH-mm-ss>
(for example, 2017-12-17-21-00-00 for December 17, 2017 at 21:00
Removing nexus
Warning: this will completely delete the current data. Be sure to back up earlier if needed
Use a variable nexus_purgeif you need to restart from scratch and reinstall the nexus instance with all data removed.
Change administrator password after first installation
nexus_default_admin_password: 'admin123'
This should not be changed in your playbook. This variable is populated with the default Nexus admin password on first install and ensures that we can change the admin password to nexus_admin_password.
If you want to change the administrator password after the first installation, you can temporarily change it to the old password from the command line. After the change nexus_admin_password in your playbook you can run: