- Community Home
- >
- Software
- >
- HPE Morpheus Software
- >
- HPE Morpheus Enterprise Software
- >
- Installing Morpheus Agent on multiple discovered V...
Categories
Company
Local Language
Forums
Discussions
- Integrity Servers
- Server Clustering
- HPE NonStop Compute
- HPE Apollo Systems
- High Performance Computing
Knowledge Base
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Knowledge Base
Forums
Discussions
- Cloud Mentoring and Education
- Software - General
- HPE OneView
- HPE Ezmeral Software platform
- HPE OpsRamp Software
Knowledge Base
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2023 08:21 PM
04-29-2023 08:21 PM
Installing Morpheus Agent on multiple discovered VMs
In this post, I want to share a script I created that automates the process of converting a list of servers to “managed” and installing the Morpheus Agent on them using the Morpheus API.
#!/bin/bash
# Parse JSON content and extract server IDs
data=$(curl -k --request GET \
--url '<%= morpheus.applianceUrl %>/api/servers?zoneId=3&managed=false&powerState=on&max=50' \
--header 'accept: application/json' \
--header 'authorization: Bearer <%= morpheus.apiAccessToken %>' | python -c "import sys, json; print('\n'.join([str(server['id']) for server in json.load(sys.stdin)['servers']]))")
# loop through the server list and install the Morpheus Agent for each server
for id in $data; do
curl -k --request PUT \
--url "<%= morpheus.applianceUrl %>/api/servers/$id/make-managed" \
--header 'accept: application/json' \
--header 'authorization: Bearer <%= morpheus.apiAccessToken %>' \
--header 'content-type: application/json' \
--data '
{
"server": {
"sshUsername": "mihai",
"sshPassword": "<%=cypher.read('password/aws-vms-pass')%>"
},
"installAgent": true
}
'
done
The script sends an HTTP GET request to the Morpheus API endpoint to retrieve a list of servers that match a specific set of criteria. The filters used in the script are:
- zoneId=3: This parameter filters the list of servers based on Cloud ID, which is set to 3 in this case.
- managed=false: This parameter filters the list of servers to exclude any servers that are already “managed”.
- powerState=on: This parameter filters the list of servers to include only servers that are powered on.
- max=50: This parameter limits the maximum number of servers that are returned by the API to 50.
These criteria can be adjusted as needed to filter the list of servers based on different conditions.
Once the script receives the JSON response from the API, it parses the data to extract the server IDs. It then loops through the list of server IDs and sends an HTTP PUT request to the API to make each server “managed” and install the Morpheus Agent on it. The script uses the curl command to send HTTP requests and the Python command to parse JSON data, so you’ll need to have these two installed on your system.
As for the SSH credentials, I have created an entry in the Morpheus Cypher module to securely store the password and referenced it in my script.
Hope it helps.
- Tags:
- API
- automation
- Tasks