This is a short post on how to install/configure the Oracle Cloud Infrastructure (OCI) Command Line Interface (CLI) on Ubuntu 20.04 LTS. On a couple of my machines I noticed the default Python3 interpreter to be 3.8.x, so I’ll stick with this version. I used the Manual installation, users with higher security requirements might want to consider the offline installation.
Creating a virtual environment
The first step is to create a virtual environment to prevent the OCI CLI’s dependencies from messing up my python installation.
[martin@ubuntu: python]$ mkdir -p ~/development/python && cd ~/development/python [martin@ubuntu: python]$ python3 -m venv oracle-cli
If this command throws an error you may have to install the virtual-env module via sudo apt install python3.8-venv
With the venv in place you need to activate it. This is a crucial step! Don’t forget to run it
[martin@ubuntu: python]$ source oracle-cli/bin/activate (oracle-cli) [martin@ubuntu: python]$
As soon as the venv is activated you’ll notice its name has become a part of the prompt.
Downloading the OCI CLI
The next step is to download the latest OCI CLI release from Github. At the time of writing version 3.0.2 was the most current. Ensure you load the vanilla release, eg oci-cli-release.zip, not one of the distribution specific ones. They are to be used with the offline installation.
(oracle-cli) [martin@ubuntu: python]$ curl -L "https://github.com/oracle/oci-cli/releases/download/v3.0.2/oci-cli-3.0.2.zip" -o /tmp/oci-cli-3.0.2.zip % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 623 100 623 0 0 2806 0 --:--:-- --:--:-- --:--:-- 2793 100 52.4M 100 52.4M 0 0 5929k 0 0:00:09 0:00:09 --:--:-- 6311k (oracle-cli) [martin@ubuntu: python]$
Unzip the release in a temporary location and begin the installation by invoking pip using the “whl” file in the freshly unzipped directory. Just to make sure I always double-check I’m using the pip executable in the virtual environment before proceeding.
(oracle-cli) [martin@ubuntu: python]$ which pip /home/martin/development/python/oracle-cli/bin/pip (oracle-cli) [martin@ubuntu: python]$ pip install /tmp/oci-cli/oci_cli-3.0.2-py3-none-any.whl Processing /tmp/oci-cli/oci_cli-3.0.2-py3-none-any.whl Collecting arrow==0.17.0 Downloading arrow-0.17.0-py2.py3-none-any.whl (50 kB) |████████████████████████████████| 50 kB 2.7 MB/s ...
You’ll notice additional packages are pulled into the virtual environment by the setup routine. As always, exercise care when using external packages. An offline installation is available as well if your security requirements mandate it.
At the end of the process you have a working installation of the command line interface.
Configuration
Before you can use the CLI you need to provide a configuration file. The default location is ~/.oci, which I’ll use as well.
(oracle-cli) [martin@ubuntu python]$ mkdir ~/.oci && cd ~/.oci
Inside of this directory you need to create a config file; the example below is taken from the documentation and should provide a starting point.
[DEFAULT] user=ocid1.user.oc1..<unique_ID> fingerprint=<your_fingerprint> key_file=~/.oci/oci_api_key.pem tenancy=ocid1.tenancy.oc1..<unique_ID> region=us-ashburn-1
Make sure to update the values accordingly. Should you be unsure about the user OCID and/or API signing key to use, have a look at the documentation for instructions. Next time you invoke the CLI the DEFAULT configuration will be used. It is possible to add multiple configurations using the old Windows 3.11 .ini file format.
[DEFAULT] user=... [ANOTHERUSER] user=...
Note that it’s strongly discouraged to store a potential passphrase (used for the API key) in the configuration file!
Happy Automation!