Add server with private key stored in database with API
How to add and update server with the private key stored in the database using API?
Overview: This article explains how to add and update a server via API using a private key stored in the database.
1. Add server via API with the private key stored in the database.
Step 1(A): Login to web GUI, navigate to Key Management -> Add new private key and passphrase(if the key was generated with passphrase). Refer to below screenshot.
Step 1(B): Log in to the gateway server and add the server via API using the key stored in the database. Use the key name from the GUI followed by db_ssh_key.
For Help
root@gateway ~]# php /usr/local/ezlogin/ezwapi.php -help add_server
Usage:
ezwapi.php add_server -api_url <API URL> -secret <API secret> -name <hostname> -password <password> -ip_address <IP address> -group <group> [-ssh_port <port>] [-rdp_port <port>] [-ssh_user <username>] [-keep_password <Y/N/S>]
[-enable_ssh <Y/N/H>] [-cp <control panel>]
-api_url : The API URL
-secret : The API secret configured in web panel settings
-name : The server host name
-description : A description for the server
-password : The server password (optional)
-ssh_key : The SSH private key file (optional)
-passphrase : The SSH key pass phrase (optional)
-db_ssh_key : The name of SSH private key saved in Ezeelogin (optional)
-ip_address : The server IP address
-ssh_port : The server SSH port (optional, use default if unspecified)
-ssh_user : The server SSH user
-switch_user : Switch to this user after login as SSH user (optional)
-switch_pass : Password for switch user (optional)
-switch_sudo : Y or N or E to escalate privilege with 'sudo su' or 'enable' (for Cisco devices) (optional, default: N = disabled)
-prompt1 : Unique string in shell prompt of SSH user (optional)
-prompt2 : Unique string in password prompt for su or sudo (optional, default: Password:)
-prompt3 : Unique string in shell prompt of root user (optional, required for sudo)
-rdp_port : The server RDP port (optional, use default if unspecified)
-group : The server group name
-keep_password : Y (keep given password), N (automatic) or S (keep server password as such - no verification) (optional, default: Y)
-enable_ssh : Y, N or H to enable/disable/via Host Node (optional, default: N)
-ishn : Y or N to make this a Host Node or not (optional, default: N)
-onhost : The name of Host Node (optional)
-cp : The control panel name (optional, use default if unspecified)
-dc : The datacenter name (optional, use default if unspecified)
-rc_host : The remote console host (optional)
-rc_user : The remote console user (optional)
-rc_pass : The remote console password (optional)
Example
root@gateway ~]# php /usr/local/ezlogin/ezwapi.php add_server -api_url http://192.168.1.35/ezlogin -secret 'Admin!2345' -name Production.server -description ubuntu.server -ssh_user root -ip_address 192.168.1.37 -group devops -enable_ssh Y -keep_password S -db_ssh_key ubuntu_private_key
200: {"status":"success","data":"Added"}
Refer detailed article for add/update/delete server using API.
Step 1(C): Login to web GUI and click on the view icon to see the name of the private key. Refer to below screenshot.
2. Update server via API with the private key stored in the database.
Step 2(A): Login to web GUI, navigate to Key Management -> Add new private key and passphrase(if the key was generated with passphrase). Refer to below screenshot.
Step 2(B): Login to the gateway server and update the server via API using the new key stored in the database. Use the new key name from the GUI followed by -db_ssh_key
For Help
root@gateway ~]# php /usr/local/ezlogin/ezwapi.php -help update_server
Usage:
ezwapi.php update_server -api_url <API URL> -secret <API secret> -name <hostname> [-newname <new hostname>] [-password <password>] [-ip_address <IP address>] [-ssh_port <port>] [-rdp_port <port>] [-ssh_user <username>]
[-group <group>] [-keep_password <Y/N/S>] [-enable_ssh <Y/N>] [-cp <control panel>]
-api_url : The API URL
-secret : The API secret configured in web panel settings
-name : The server host name
-newname : The new host name (optional)
-description : A description for the server
-password : The server password (optional)
-ssh_key : The SSH private key file (optional)
-passphrase : The SSH key pass phrase (optional)
-db_ssh_key : The name of SSH private key saved in Ezeelogin (optional)
-ip_address : The server IP address (optional)
-ssh_port : The server SSH port (optional)
-ssh_user : The server SSH user (optional)
-switch_user : Switch to this user after login as SSH user (optional)
-switch_pass : Password for switch user (optional)
-switch_sudo : Y or N or E to escalate privilege with 'sudo su' or 'enable' (for Cisco devices) (optional, default: N = disabled)
-prompt1 : Unique string in shell prompt of SSH user (optional)
-prompt2 : Unique string in password prompt for su or sudo (optional)
-prompt3 : Unique string in shell prompt of root user (optional, required for sudo)
-rdp_port : The server RDP port (optional, use default if unspecified)
-group : The server group name
-keep_password : Y (keep given password), N (automatic) or S (keep server password as such - no verification) (optional)
-enable_ssh : Y, N or H to enable/disable/via Host Node (optional)
-ishn : Y or N to make this a Host Node or not (optional)
-onhost : The name of Host Node (optional)
-cp : The control panel name (optional)
-dc : The datacenter name (optional)
-rc_host : The remote console host (optional)
-rc_user : The remote console user (optional)
-rc_pass : The remote console password (optional)
Example
root@gateway ~]# php /usr/local/ezlogin/ezwapi.php update_server -api_url http://192.168.1.35/ezlogin -secret 'Admin!2345' -name Production.server -description developing server -ip_address 192.168.1.37 -group devops -ssh_port 22 -newname db.noc.com -db_ssh_key new_ssh_private_key
200: {"status":"success","data":"Saved"}
Step 2(C): Login to web GUI and click on the view icon to see the updated server with the new private key. Refer below screenshot.
Related Articles:
Add/Update/Delete servers using API
Is it possible to add a user using API?
Error: Wrong passphrase or corrupted key