How to create nexus user and roles using the ansible playbook

How can i create nexus user and roles using the ansible playbooks.
I am trying to automate nexus and user creation process.
However so far i have installed nexus using the playbook, i am stuck at user and role creation step. please help

Hi!
I think this project can help you: GitHub - ansible-ThoTeam/nexus3-oss: Ansible role to install and provision sonatype nexus3-oss

2 Likes

Thank you for your time to look at the problem, I went through this project before, but could not get it how the user is getting created, the only thing i could identify and use is to put the lines of code in defaults for the user and variable roles declaration, but how author is using those defaults and creating the user/role is something I couldnt understand.

Well this project uses inside Ansible role Groovy scripts.

As example:
// add a local user account with the role security.addUser("devuser", "Delilah", "Developer", "companydev@mycompany.com", true, "devpassword", [ role.roleId ])

This simple script will create a user with following parameters. But you can use your own parameters with Json_slurper and it will be look something like this:

import org.sonatype.nexus.*
security.addUser(userId:"$parsed_args.userId",
                firstName: "$parsed_args.firstName", 
                lastName: "$parsed_args.lastName",
                emailAddress: "$parsed_args.emailAdress");```

And you can pass this arguments via external json file, as example:
`{
  "userId":"CoolUser",
  "firstName":"Dmitry",
  "lastName": "SomeLastName",
  "emailAddress": "dmitry@companyname.com"
}`

As main point of confusion - you still need to write some checks that this user present or not. Also you need to study project (or write your own) to understand how this parameter get into your script. I can't help you with that because I'm not good in Groovy or programming at all, may be some more experienced guys will give you a hand with that, I can give only the starting point to that.

Also how to put your scripts to Nexus server is here: https://help.sonatype.com/repomanager3/rest-and-integration-api/script-api
https://help.sonatype.com/repomanager3/rest-and-integration-api/script-api/managing-and-running-scripts