User Data¶
When provisioning a server on Equinix Metal™ you have the option to include User Data, which can be used to perform various automation tasks after the server is ready, such as executing common scripts / packages, or triggering other more advanced configuration processes.
User data - like other forms of instance “meta data” - is tied into Equinix Metal’s extensive use of cloud-init. Designed in the early days of AWS, Cloud-init is a simple but powerful technique for carrying out actions on a cloud instance at boot time. It takes care of defining each machine’s hostname, adds SSH keys, and performs the “phone home” process when the server finishes provisioning.
User Data allows you to influence and augment this critical part of the server provisioning process.
Usage¶
Userdata takes two different forms:
User Data Script
- Typically used by those who just want to execute a shell script.
- Begins with: #! for Linux shell or #ps1 for Windows Powershell
Cloud Config Data
- Using valid yaml syntax, you can specify certain things in a human friendly format.
- Begins with: #cloud-config
When provisioning a new server from the Equinix Metal console, you add User Data by expanding the Optional Settings.
On the other hand, if you want to provision a server via our API, you can add userdata by simply using the "userdata": "string" in the body of the call.
Example Usage¶
User Data Script
Linux:
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get upgrade -y
apt-get install nginx -y
#ps1
New-Item C:/Users/Admin test.txt
Set-Content C:/Users/Admin/test.txt "Hello world"
$password = ConvertTo-SecureString "P@55w0rd!" -AsPlainText -Force
New-LocalUser -Name "user01" -Password $password
Cloud-Config
Linux:
#cloud-config
package_upgrade: true
packages:
- nginx
Windows: Windows can accept cloud-config scripts, but the has some limitations compared to linux. See Cloudbase-init's documentation on user data for a more information on cloud-config scripts.
Troubleshooting Tips¶
The first thing to keep in mind when using any form of user data, is that depending on the length of your script, you need to give it some time to execute after seeing the server as “Active” in the Equinix Metal portal.
If you need to check whether the server has downloaded the user-data at all, you can check
/var/lib/cloud/instance/user-data.txt
Any form of user data will only run on the first boot, and you won’t be able to rerun it again later on the same server.
If you need to troubleshoot any issues, the log files where you can get any needed information are
/var/log/cloud-init.log and /var/log/cloud-init-output.log