3 Environment Variables and Profile Files

You can provide credentials and other configuration information using environment variables, profile files, and command line arguments.

Here’s the order of precedence (the first option has the highest precedence):

  1. The values, such as -pf and -u, that you specify at the command line take precedence over all other options.

  2. When you don’t provide command line arguments, the values specified in the environment variables, such as OPC_COMPUTE_USER and OPC_COMPUTE_PASSWORD_FILE, take precedence over the values provided in the profile file.

  3. When you don’t specify values for command line arguments and environment variables, values specified in the profile file are considered.

About Environment Variables

The following table lists all the environment variables you can use in Compute Classic CLI. It is not mandatory to specify values for any of these environment variables. You can specify values for one or more environment variables depending on how you want to interact with the CLI. Values that you specify in the environment variables override the values specified in the profile file. However, the values you specify at the command line override all the other values.

Environment Variable Description
DEBUG

Set this to true to run commands in debug mode. The output in this mode is very verbose. It includes the request and response details of the internal API call that is invoked for the CLI command. You can use this output for debugging issues.

The default value is false.

You can set the environment variable from the Bash shell as shown in the following example:

export DEBUG="true"
OPC_COMPUTE_COOKIE

Store the authentication cookie value in this environment variable. An authentication cookie is created when you run the Authentication command.

OPC_COMPUTE_ENDPOINT

Store the REST API endpoint URL of your Compute Classic site in this environment variable. To find out the REST API endpoint URL of your site, follow the instructions at Send Requests in REST API for Oracle Cloud Infrastructure Compute Classic.

You can set the environment variable from the Bash shell as shown in the following example:

export OPC_COMPUTE_ENDPOINT="api-z999.compute.us0.oraclecloud.com"
OPC_COMPUTE_PASSWORD_FILE

Name of the plain-text file that contains the password for authenticating access to Compute Classic.

The account creation email from Oracle would contain the password for your Compute Classic instance.

Ensure that the file containing the password isn't world-readable.

You can set the environment variable from the Bash shell as shown in the following example:

export OPC_COMPUTE_PASSWORD_FILE="/full/path/of/password-file"
OPC_COMPUTE_USER

Two-part user name (/Compute-identity_domain/user).

The account creation email from Oracle would contain the identity domain name and user name for your Compute Classic instance.

For example, if your identity domain is acme and the username in your account-creation email is jack.jones@example.com, then the following would be the two-part user name that you must use for running CLI commands: /Compute-acme/jack.jones@example.com.

You can set the environment variable from the Bash shell as shown in the following example:

export OPC_COMPUTE_USER="/Compute-acme/jack.jones@example.com"
OPC_FIELDS

Comma separated fields for table output.

Lists values only for the specified resource attributes. You can use this option to filter the output to show only the attributes that you want to see, particularly for objects that have numerous attributes.

You can use this option only when you have specified that the output should be displayed in tabular format.

You can set the environment variable from the Bash shell as shown in the following example:

export OPC_FIELDS="name,status"
OPC_FORMAT

Specify one of the following formats in which you want the output to be displayed: json or table. The default value for this environment variable is json.

You can set the environment variable from the Bash shell as shown in the following example:

export OPC_FORMAT="table"
OPC_PROFILE_FILE

Name of the text file that contains the user name and password for authenticating access to Compute Classic. It also contains information about the REST API endpoint URL for your Compute Classic site.

For information about creating a profile, see Setting Up the Required Environment Variables and Files.

Note that the file must not be world-readable.

The default value for this environment variable is default which points to the ~/.opc/profile/default profile file.

You can set the environment variable from the Bash shell as shown in the following example:

export OPC_PROFILE_FILE="name-of-profile-file"
OPC_PROFILE_DIRECTORY

The folder that contains the file name that you specify using the --profile or -p option.

The default value for this environment variable is ~/.opc/profiles.

You can set the environment variable from the Bash shell as shown in the following example:

export OPC_PROFILE_DIRECTORY="/full/path/of/profile-directory"

Tip:

To make the environment variables persist across login sessions, add the export commands described earlier to your .bash_profile or .bashrc file.

Setting Up Environment Variables and Files

While running the Compute Classic CLI commands, you must provide the user name, password, and REST API endpoint URL. There are many ways in which you can provide these values. You can use any one of these following ways based on your requirement.

On the host on which you installed the CLI client, do one of the following:

  1. Note down the REST API endpoint URL of your Compute Classic site. To find out the REST API endpoint URL of your site, follow the instructions at Send Requests in REST API for Oracle Cloud Infrastructure Compute Classic.

  2. Note down your two-part user name (/Compute-identity_domain/user).

    The account creation email from Oracle would contain the identity domain name, user name, and password for your Compute Classic instance, as shown in the following example:

    Account creation email from Oracle contains the name of the identity domain, user name, and password.

    If you don't have this information, contact your service administrator.

    Note:

    The user name consists of two parts, in the following format:

    /Compute-identity_domain/user

    For example, if your identity domain is acme and the username in your account-creation email is jack.jones@example.com, then the following would be the two-part user name that you must use for running CLI commands:

    /Compute-acme/jack.jones@example.com

  3. Store your password in a plain-text file of your choice (for example, in your /home/user directory).

    Ensure that the file containing the password isn't world-readable, by changing the permission to 600.

    chmod 600 /full/path/to/password/file
    
  4. While running the Compute Classic CLI commands, you must provide the user name, password, and REST API endpoint URL in one of the following ways:

    • Option 1: Create a profile to store your user name, password, and REST API endpoint URL.

      1. Create a directory where you want to save your profile file. For example, ~/.opc/profiles.

      2. Create a new file in this folder. In this example, let’s create a profile with the file name profile-jack.

        vi profile-jack
        
        {
          "global": {
            "format": "json",
            "debug-requests": false
          },
          "compute": {
            "user": "/Compute-identity_domain/user",
            "password-file": "/full/path/to/password/file",
            "endpoint": "api-z999.compute.us0.oraclecloud.com"
          }
        }

        Replace user, password-file, and endpoint with values that are specific to your environment.

        In the profile file, you can also specify values for the global options. In this example, under global options, JSON is specified as the output format and that the commands should not be executed in debug mode.

      3. Ensure that the profile file isn't world-readable, by changing the permission to 600.
        chmod 600 /full/path/to/profile/file
        
      4. Store the name of the profile file in the OPC_PROFILE_FILE environment variable. The default value of this variable is default which points to the ~/.opc/profile/default profile file.
        export OPC_PROFILE_FILE="name-of-profile-file"
      5. Store the name of the folder in which the profile file is located in the OPC_PROFILE_DIRECTORY environment variable. The default value of this variable is ~/.opc/profiles.

        export OPC_PROFILE_DIRECTORY="/full/path/of/profile-directory"

        If you don't set the OPC_PROFILE_DIRECTORY and OPC_PROFILE_FILE environment variables, you must specify these values at the command line. Use the -p and -pd options at the command line to specify the name of the profile file and its location respectively.

      Tip:

      To make the environment variables persist across login sessions, add the export commands described earlier to your .bash_profile or .bashrc file.

    • Option 2: Set up environment variables.

      If you specify credentials in environment variables, then these credentials take precedence over the credentials specified in the profile file.

      • Store the REST API endpoint URL of your Compute Classic site in an environment variable named OPC_COMPUTE_ENDPOINT.

        You can set the environment variable from the Bash shell as shown in the following example:

        export OPC_COMPUTE_ENDPOINT="api-z999.compute.us0.oraclecloud.com"
        
      • Store your two-part user name (/Compute-identity_domain/user) in an environment variable named OPC_COMPUTE_USER.

        You can set the environment variable from the Bash shell as shown in the following example:

        export OPC_COMPUTE_USER="/Compute-acme/jack.jones@example.com"
        
      • Store the location of your password file in an environment variable named OPC_COMPUTE_PASSWORD_FILE.

        You can set the environment variable from the Bash shell as shown in the following example:

        export OPC_COMPUTE_PASSWORD_FILE="/full/path/to/password/file"
        

        Tip:

        To make the environment variables persist across login sessions, add the export commands described earlier to your .bash_profile or .bashrc file.

    • Option 3: Use command line arguments.

      If you specify credentials at the command line, then these credentials take precedence over the credentials specified using the other methods.

      If you don't set the environment variables or create a profile file, then while running every command you must explicitly specify the REST API endpoint URL by using the -e option, the user name by using the -u option, and the password by using the -pf option as described in Service Options.

You can now run the Compute Classic CLI commands.