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

Ansible role is failing during update from Nexus 3.71.1-06 to 3.72.0-04 #431

Open
uwehdaub opened this issue Oct 7, 2024 · 9 comments
Open

Comments

@uwehdaub
Copy link

uwehdaub commented Oct 7, 2024

During the update from Nexus 3.71.1 to 3.72.0 the role (v2.5.1) fails with the following error message:

TASK [ansible-thoteam.nexus3-oss : Create/Check blobstores] ********************************************************************************************************************
included: /home/uwe/.ansible/roles/ansible-thoteam.nexus3-oss/tasks/call_script.yml for dxnexustest0.ciserver.dxnexus.test1.peng.be-gcw1.metroscales.io

TASK [ansible-thoteam.nexus3-oss : Calling Groovy script create_blobstores_from_list] ******************************************************************************************
fatal: [dxnexustest0.ciserver.dxnexus.test1.peng.be-gcw1.metroscales.io]: FAILED! => {"changed": false, "connection": "close", "content_length": "278", "content_type": "application/json", "date": "Mon, 07 Oct 2024 10:58:08 GMT", "elapsed": 0, "failed_when_result": true, "json": {"name": "create_blobstores_from_list", "result": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"}, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "redirected": false, "server": "Nexus/3.72.0-04 (OSS)", "status": 400, "url": "http://localhost:8081/service/rest/v1/script/create_blobstores_from_list/run", "x_content_type_options": "nosniff"}

TASK [ansible-thoteam.nexus3-oss : Debug script result for global fail] ********************************************************************************************************
skipping: [dxnexustest0.ciserver.dxnexus.test1.peng.be-gcw1.metroscales.io]

TASK [ansible-thoteam.nexus3-oss : Global script failure at nexus level] *******************************************************************************************************
skipping: [dxnexustest0.ciserver.dxnexus.test1.peng.be-gcw1.metroscales.io]

TASK [ansible-thoteam.nexus3-oss : Debug script result for failed script actions] **********************************************************************************************
ok: [dxnexustest0.ciserver.dxnexus.test1.peng.be-gcw1.metroscales.io] => {
    "msg": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"
}

TASK [ansible-thoteam.nexus3-oss : Script action failure] **********************************************************************************************************************
fatal: [dxnexustest0.ciserver.dxnexus.test1.peng.be-gcw1.metroscales.io]: FAILED! => {"changed": false, "msg": "The script create_blobstores_from_list returned at least one of its actions has failed. See the degug message above for details"}

PLAY RECAP *********************************************************************************************************************************************************************
dxnexustest0.ciserver.dxnexus.test1.peng.be-gcw1.metroscales.io : ok=87   changed=1    unreachable=0    failed=1    skipped=56   rescued=1    ignored=0   

The playbook was running on Ubuntu 20.04.6 LTS (GNU/Linux 5.15.0-1060-gcp x86_64).

Ansible role v2.5.2 fails with the same error message.

@ismoilovdevml
Copy link

I have the same problem

TASK [ansible-ThoTeam.nexus3-oss : Calling Groovy script create_blobstores_from_list] ********************************************************************************************************
fatal: [ubuntu]: FAILED! => {"changed": false, "connection": "close", "content_length": "278", "content_type": "application/json", "date": "Mon, 07 Oct 2024 21:02:25 GMT", "elapsed": 0, "failed_when_result": true, "json": {"name": "create_blobstores_from_list", "result": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"}, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "redirected": false, "server": "Nexus/3.72.0-04 (OSS)", "status": 400, "url": "http://localhost:8081/service/rest/v1/script/create_blobstores_from_list/run", "x_content_type_options": "nosniff"}
fatal: [debian]: FAILED! => {"changed": false, "connection": "close", "content_length": "278", "content_type": "application/json", "date": "Mon, 07 Oct 2024 21:02:26 GMT", "elapsed": 1, "failed_when_result": true, "json": {"name": "create_blobstores_from_list", "result": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"}, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "redirected": false, "server": "Nexus/3.72.0-04 (OSS)", "status": 400, "url": "http://localhost:8081/service/rest/v1/script/create_blobstores_from_list/run", "x_content_type_options": "nosniff"}
fatal: [rockylinux]: FAILED! => {"changed": false, "connection": "close", "content_length": "278", "content_type": "application/json", "date": "Mon, 07 Oct 2024 21:02:26 GMT", "elapsed": 1, "failed_when_result": true, "json": {"name": "create_blobstores_from_list", "result": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"}, "msg": "Status code was 400 and not [200]: HTTP Error 400: Bad Request", "redirected": false, "server": "Nexus/3.72.0-04 (OSS)", "status": 400, "url": "http://localhost:8081/service/rest/v1/script/create_blobstores_from_list/run", "x_content_type_options": "nosniff"}

TASK [ansible-ThoTeam.nexus3-oss : Debug script result for global fail] **********************************************************************************************************************
skipping: [debian]
skipping: [rockylinux]
skipping: [ubuntu]

TASK [ansible-ThoTeam.nexus3-oss : Global script failure at nexus level] *********************************************************************************************************************
skipping: [debian]
skipping: [ubuntu]
skipping: [rockylinux]

TASK [ansible-ThoTeam.nexus3-oss : Debug script result for failed script actions] ************************************************************************************************************
ok: [debian] => {
    "msg": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"
}
ok: [ubuntu] => {
    "msg": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"
}
ok: [rockylinux] => {
    "msg": "javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.sonatype.nexus.internal.provisioning.BlobStoreApiImpl.getBlobStoreManager() is applicable for argument types: () values: []"
}

TASK [ansible-ThoTeam.nexus3-oss : Script action failure] ************************************************************************************************************************************
fatal: [debian]: FAILED! => {"changed": false, "msg": "The script create_blobstores_from_list returned at least one of its actions has failed. See the debug message above for details"}
fatal: [ubuntu]: FAILED! => {"changed": false, "msg": "The script create_blobstores_from_list returned at least one of its actions has failed. See the debug message above for details"}
fatal: [rockylinux]: FAILED! => {"changed": false, "msg": "The script create_blobstores_from_list returned at least one of its actions has failed. See the debug message above for details"}

PLAY RECAP ***********************************************************************************************************************************************************************************
debian                     : ok=56   changed=1    unreachable=0    failed=1    skipped=44   rescued=1    ignored=0   
rockylinux                 : ok=58   changed=1    unreachable=0    failed=1    skipped=42   rescued=1    ignored=0   
ubuntu                     : ok=55   changed=1    unreachable=0    failed=1    skipped=44   rescued=1    ignored=0 

@brianveltman
Copy link
Contributor

I will provide a fix for this tomorrow. Thanks for reporting! Bumping into the same issue tho.

@uwehdaub
Copy link
Author

See sonatype/nexus-public#485

@Koeppchen
Copy link

Koeppchen commented Oct 14, 2024

I could not find a good way to access the blobStoreManager and we do not use the actual Codebase.
What worked for us, but what is really hacky is the folowing:

`
import org.sonatype.nexus.blobstore.api.BlobStoreManager
import java.lang.reflect.Field

// Hack to access BlobStore Manager, access was removed in Nexus 3.72 because Groovy implemetation was replaced by Java and the field was made private
Field  privateField = blobStore.class.getDeclaredField("blobStoreManager")
privateField.setAccessible(true)
BlobStoreManager blobStoreManager = (BlobStoreManager)privateField.get(blobStore)
//... other Code
existingBlobStore = blobStoreManager.get("BlobStoreName")
```
`

@brianveltman
Copy link
Contributor

See #432 for a better fix, since Sonatype officially does not support Groovy scripts anymore.
Will add more automated molecules tests for this change later this week, but this should get you guys up & running with the latest version of Nexus Repository Manager.

@LordAro
Copy link

LordAro commented Nov 21, 2024

@Koeppchen Beautifully hacky. Works great - here's my diff for reference

--- files/groovy/create_blobstores_from_list.groovy.orig      2024-11-21 17:40:45.984749159 +0000
+++ files/groovy/create_blobstores_from_list.groovy   2024-11-21 17:39:37.285848807 +0000
@@ -1,6 +1,14 @@
 import groovy.json.JsonOutput
 import groovy.json.JsonSlurper

+// Hack to access BlobStore Manager, access was removed in Nexus 3.72 because Groovy implemetation was replaced by Java and the field was made private
+import org.sonatype.nexus.blobstore.api.BlobStoreManager
+import java.lang.reflect.Field
+
+Field privateField = blobStore.class.getDeclaredField("blobStoreManager")
+privateField.setAccessible(true)
+BlobStoreManager blobStoreManager = (BlobStoreManager)privateField.get(blobStore)
+
 parsed_args = new JsonSlurper().parseText(args)

 List<Map<String, String>> actionDetails = []
@@ -11,7 +19,8 @@

     Map<String, String> currentResult = [name: blobstoreDef.name, type: blobstoreDef.get('type', 'file')]

-    existingBlobStore = blobStore.getBlobStoreManager().get(blobstoreDef.name)
+    //existingBlobStore = blobStore.getBlobStoreManager().get(blobstoreDef.name)
+    existingBlobStore = blobStoreManager.get(blobstoreDef.name)
     if (existingBlobStore == null) {
         try {
             if (blobstoreDef.type == "S3") {

(@brianveltman's change may well be the better fix, but I have no idea where it is in that massive diff of changes)

@zeitounator
Copy link
Member

zeitounator commented Nov 21, 2024

@LordAro I don't think I'd have found that hack alone ! Kudos ! One of my team mate was actively waiting for this. Cheers. I'm going to merge this ASAP.

@brianveltman
Copy link
Contributor

brianveltman commented Nov 21, 2024

I have actively worked on a fork of this repo over the last year since I needed to move forward for a project im working on together with the support of Sonatype.

A lot of issues and PR's addressed in this repository have been either merged, fixed or incorporated in a different way into my fork.

Issues fixed: #289 #335 #408 #410 #427 #431 #433 #434
PRs merged or provided alternative solution for: #254 #409 #412 #413 #416 #417 #424 #426 #430 #432 #435 #437

I've also been actively working on a new Ansible collection for Nexus3 that has more smaller roles that strictly make a distinction between provisioning tasks (i.e changing, updating, deleting infrastructural parts before installing Nexus) and configuration tasks (i.e everything done after a Nexus install)

The configuration tasks in this new role is using API endpoints only, this way we're sure Nexus wont be restarted when a configuration item is processed and it doesn't rely on groovy/java classes anymore. This way the role can be used with any Nexus instance on VMs, bare metal, containers, clusters, HA setup etc..

Also an important note: this new role strictly enforces 'desired-state-config' principles. Meaning any configuration (including repositories) that's not defined in the Ansible variables will be deleted or set to the Nexus default where applicable.

A lot of API endpoints associated with configuring Nexus are supported in this new role, except for:

  • Cargo repo endpoints (planned next week)
  • Rubygems repo endpoints (planned next week)
  • HTTPS System settings (Work in progress)
  • IQ Repo Firewall (planned next week
  • Tasks (planned next week)

Planned early 2025:

  • Blob store PUT endpoints
  • Azure Blob store endpoint
  • Google Blob store endpoint
  • Security Management SAML
  • Email endpoint
  • Security Atlassian Cloud
  • Security Management Privileges
  • Tags

@brianveltman
Copy link
Contributor

The collection has been published at Galaxy; https://galaxy.ansible.com/ui/repo/published/cloudkrafter/nexus/ and its repo can be found at: https://github.com/CloudKrafter/nexus-ansible-collection

Updates since my last comment:

  • Cargo and rubygems repos are supported now
  • Managing User-tokens, LDAP, SSL Certificate Store and Routing Rules
  • Creating and deleting S3, File and Group blobstores
  • Managing Security Realms (and the order of realms)
  • A heavily modified copy of this nexus_oss role has been included, fixing or implementing the issues described above, plus added support for running Nexus Pro in clustered mode.
  • All used variables are compatible with this role
  • Using custom normalizing filters to transform yaml dictionaries to the proper API payload.

I'm working on a custom normalizing filter to handle the transformation of all repository definitions so the new role (config_api) will accept any nexus_repos_*_* definition to configure, update or delete the defined assets through the API.

What's planned for early 2025 has not been changed.
However the proposed changes for 2025 only affect the config_api role and not the modified nexus_oss role, that role is fully compatible with this role.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants