How to use Morpheus CLI commands in ansible playbooks

Hi All, Is there any to guide me.
Iam trying to download, install and configure Morpheusdata using ansible playbook. I have done download, install, reconfigure, changed Appliance name. Now I want to use cli commands in ansible playbook to do initial setup. I have tried but it’s not working.
I tried with the following syntax.
Screenshot 2023-05-17 103247

and with this syntax both are not working.
Screenshot 2023-05-17 103558

Thanks a lot.

Hi,
I think you’d be better doing this via the Morpheus API in a playbook instead of the CLI.
We have an example of an ansible task in the gomorpheus repo that does exactly this. You can find the task here

Thanks
Pete

thank you Pete,
but my requirement is with CLI. If any idea about CLI kindly share.
Thanks
Basharat

You would need to be more specific about what is not working. The CLI isn’t really designed to be used in scripts or any other non-interactive way. In fact, the CLI just translates your inputs into API calls and sends them to Morpheus.

If you are getting prompts in Ansible from the CLI, most commands have a -N flag that will disable prompting for input. If you don’t have all the required information in the CLI command, you will receive an error, so you will have to test your inputs.

I am trying to automate the download, install and configure and automate the initial setup of morpheusdata using ansible playbook. I have downloaded, installed and configured the morpheusdata using ansible playbook. but the initial setup is not working.
Screenshot 2023-05-17 103558
When i use the above syntax it is changing the appliance name but it is not prompting for the other details, like user name, email etc.
It is possible to do using cli command in ansible playbook. If it is possible then how would it be.
please guide.

Thanks
Basharat

Ansible is not interactive. You can attempting to run a command that is interactive and expects user input. You would need to find a way to have Ansible respond to requests for input from the script. I’ve been using Ansible for over 7 years and I would be hard pressed to make that work.

The correct way to perform this task is to use the API through Ansible. If you must use the CLI, Ansible is the wrong tool to perform that task.

Ok thank you Celebic
How can I perform the same task using API. Kindly suggest me example or documents

@pjones provided you an Ansible example for using the API above. The API documentation is located here: https://apidocs.morpheusdata.com

Your specific ask for setup is here: https://apidocs.morpheusdata.com/reference/setup-1

1 Like

Ok thanks a lot.
I thought you might have any other example.

There are a few API payload examples in the apidocs. It’s on the right side.

Got it, thanks!

Hi, @pjones @ncelebic
I am using the example @pjones provided like this.


Screenshot 2023-05-18 120635

But the error is below

fatal: [localhost]: FAILED! => {“cache_control”: “no-cache, no-store”, “changed”: false, “connection”: “close”, “content_security_policy”: “default-src ‘self’ https://www.gstatic.com *.githubusercontent.com data: blob: ws: wss:; base-uri ‘self’; object-src ‘none’; script-src ‘self’ ‘nonce-LQf8lBcuwQTwgOMf’ ‘unsafe-inline’ ‘strict-dynamic’ https://www.gstatic.com; style-src ‘self’ ‘unsafe-inline’ https://www.gstatic.com”, “content_type”: “application/json;charset=UTF-8”, “date”: “Thu, 18 May 2023 06:47:45 GMT”, “elapsed”: 1, “expires”: “-1”, “feature_policy”: “vibrate ‘none’ ; microphone * ; camera ‘none’ ; gyroscope ‘none’ ; magnetometer ‘none’ ; geolocation ‘none’ ; midi ‘self’ ; notifications ‘self’ ; push ‘self’ ; sync-xhr ‘self’”, “json”: {“errors”: {}, “msg”: “Failed to register with Morpheus Hub”, “success”: false}, “msg”: "Status code was 400 and not [200]: HTTP Error 400: ", “pragma”: “no-cache”, “redirected”: false, “referrer_policy”: “same-origin”, “set_cookie”: “XSRF-TOKEN=169f8767-0b92-41c4-a4b6-6b1d03b0564e; Path=/; Secure; HttpOnly”, “status”: 400, “strict_transport_security”: “max-age=31536000”, “transfer_encoding”: “chunked”, “url”: “https://192.168.4.241/api/setup”, “vary”: “Access-Control-Request-Headers”, “x_content_type_options”: “nosniff”}

Thanks
Basharat

The error you are getting is a failure to register with the Morpheus hub. There could be a number of environmental issues causing this. Try setting the variable morpheus_setup_hub_mode to skip. This will bypass hub registration and then you can confirm if the set up works.

I need to register if I skip the registration then I have to register manually. I don’t want this.

When I set the variable morpheus_setup_hub_mode to skip then all tasks execute with ok status without any error but skipped registration.

I have tested this using the same playbooks and the registration to the hub works fine.

If running the playbook on a multi-node Morpheus setup e.g 3 node HA, the setup task only needs to run once. If it runs on all 3 you will see the error that you get on 2 of the nodes. But on the node where the task runs, registration to the hub will work fine. Try and log into the hub using the user that you specified in the setup to check if the appliance has registered.

The initial start-up of Morpheus can take a few minutes as the database is seeded and plugins are loaded. You will need to factor this in to make sure that the setup task only runs after the application has completely started. You can check in the morpheus-ui current log file to see when the application startup has completed. Look for the Morpheus logo.

I am using single Node. I am not using 3 node HA.

The password you are specifying to register with the hub does not meet the minimum password requirements (8 charactes, 1 uppercase, 1 symbol). This will be the reason for the failure.

Ok thank you I will check.