Automating everything in your Nexus 3.x Repository Manager
Sonatype Nexus have gone a long way providing us DevOps with cool tools for automating probably anything you can dream of, they could do a much better job of documenting what is/isn’t supported Nonetheless Nexus considering it’s restful API + the great Ansible role by Samuel Hervé & great help from Dan Hirsch on the Docker repository management + yours truly you can actually automate anything.
Before I Drill Down into it there is a full working sample in this github repo
Let’s drill down into the role and see how you can automate let’s say a scheduled task of backing up Nexus configuration on a nightly basis (without doing too much coding …).
- taking look at the var file defaults/main.yml you control the version of Nexus recently updated to the latest version 3.2.1-01 you will find the version:
I am mentioning this because the backup feature was added in version 3.2.1-01 which was released Feb 6, 2017 which supports this feature out of the box ;)
- In order to add a scheduled task or any other Nexus feature you can take a close look at the nexus role and see that all you need to come up with is the required payload to pass to a script which already resides in the role called create_task.groovy:
- This script is firstly added to the Nexus via the add_script task:
- And declare_script_each basically registers the groovy script against the Nexus API like so:
- So in our case, all is left is to find the correct payload to pass to the script in order to create our schedule task. With a little help from Postman which offers an A Complete Toolchain for API Development part of that is a plugin for chrome which helps you do the following:
Get Nexus up and running in my case the Nexus URL is on my local development environment at http://172.16.1.160:8081
Configure postman to monitor all traffic via browser and as a tip filter only the ip/hostname of you nexus instance like so:
- In Nexus UI login and land onto the scheduled tasks creation page:
- Record the payload passed to Nexus with Postman:
- _Small tip in order to identify the payload you can intercept just a second before you press the create button in the Postman desktop app, otherwise you will have a lot of work finding the specific payload. In the macOS version the option is in postman’s top bar:
Let’s put this all together into our nexus role/playbook
Run the playbook
bash # get code git clone firstname.lastname@example.org:shelleg/ansible-playbook-nexus3.git # get requirements ansible-galaxy install -r requirements.yml # run vagrant vagrant up nexus
- View our final result (I took a sample using cron):
In edit view:
Hope you find this useful.
We will contact you as soon as possible.