How do I deploy Linodes from a saved image using the Linode CLI?
I'd like to be able to deploy Linodes from a saved image using linode-cli
instead of having to enter the details every time using the browser. How can I do this?
1 Reply
To deploy from a saved image using the Linode CLI, you'll first need to get the images ID. To obtain the ID for an example image named testimage
, you'd run the following command:
$ linode-cli images list --text | awk '/testimage/{print $1}'
private/5877828
You can also just use linode-cli images list
, but the command above will return only the data you need, and nothing else.
In the case above, the image testimage
has an ID of private/12345
. You can then use that ID to deploy from an image using a command like the following:
# Replace 'private/12345' with your image's ID
# Be sure to enter the IMAGE'S ID (e.g. 'private/12345')
# and NOT the LABEL (e.g. 'testimage')
$ linode-cli linodes create --label "$LABEL" \
--region "$REGION" \
--root_pass "$PASSWORD" \
--image 'private/12345' \
--type "$PLAN_TYPE" \
--authorized_keys "$SSH_PUBLIC_KEY"
You can also script the process of obtaining the image ID and creating the Linode like this:
# Replace 'testimage' with your image's label
# Be sure to enter the LABEL (e.g. 'testimage')
# and NOT the IMAGE'S ID (e.g. 'private/12345')
IMAGE_ID="$(linode-cli images list --text | awk '/testimage/{print $1}')"
linode-cli linodes create --label "$LABEL" \
--region "$REGION" \
--root_pass "$PASSWORD" \
--image "$IMAGE_ID" \
--type "$PLAN_TYPE" \
--authorized_keys "$SSH_PUBLIC_KEY"
I've included our APIv4 Documentation, which also includes examples for the Linode CLI, for your reference.