Retrieve Predefined Instance Metadata

Two types of metadata are stored within your instances: user-defined instance attributes that you can define explicitly while creating instances, and predefined instance metadata fields that are stored by default for all instances.

Scripts and applications running on the instances can use the available metadata to perform certain tasks. For example, SSH public keys that are specified while creating an instance are stored as metadata on the instance. A script running on the instance can retrieve these keys and append them to the authorized_keys file of specified users to allow key-based login to the instance using ssh.
  1. Log in to the instance.
  2. Get a list of the available metadata versions by running the following command:
    curl http://192.0.0.192
  3. From the list of versions displayed, select the version that you want to use.
  4. Get a list of the top-level metadata fields:
    curl http://192.0.0.192/{version}/meta-data
    
    In this command, replace {version} with the version that you identified in the previous step.
    Example:
    curl http://192.0.0.192/2007-08-29/meta-data
    
  5. Retrieve the specific metadata that you want, by running one of the following command examples:

    Note:

    When you run these commands, replace 2007-08-29 with the metadata version that you want to use.

    • To retrieve the private IP address of the instance:
      curl http://192.0.0.192/2007-08-29/meta-data/local-ipv4
      10.106.15.70
    • To retrieve the host name of the instance:
      curl http://192.0.0.192/2007-08-29/meta-data/local-hostname
      bd6032.acme.oraclecloud.com
    • To retrieve information about the memory and CPU resources of the instance:
      curl http://192.0.0.192/2007-08-29/meta-data/instance-type
      7680 ram, 2.0 cpus
    • To retrieve the instance name:
      curl http://192.0.0.192/2007-08-29/meta-data/instance-id
      /Compute-acme/joe.jonathan@example.com/4c318760-444b-4b48-83e1-e1b112c201f2
    • To find out how many SSH public keys are stored on the instance:
      curl http://192.0.0.192/2007-08-29/meta-data/public-keys
      0
      1
      2
      In this example, three SSH public keys are stored as metadata, with index numbers 0, 1, and 2.
    • To retrieve the value of a specific SSH public key:
      curl http://192.0.0.192/2007-08-29/meta-data/public-keys/0/openssh-key
      ssh-rsa AAAAB3NzaC1yc2EAAAABI... == joe.jonathan@acme.com