Using Oracle Linux 8.10 in WSL for Oracle Cloud Infrastructure Ansible Collection

In this blog post, we will guide you through the process of setting up Oracle Linux 8.10 in Windows Subsystem for Linux (WSL) to effectively work with the Oracle Cloud Infrastructure (OCI) Ansible Collection. We’ll cover installation, necessary packages, OCI CLI setup, and a test of the setup. One of the great features of WSL is its seamless integration with Visual Studio Code (VS Code). This powerful code editor provides excellent support for remote development, allowing you to edit files, run commands, and manage your environment directly within the editor.

Table of Contents

  1. Installing Oracle Linux 8.10 from the Windows Store
  2. Installing Missing OS Packages
  3. Installing and configure OCI-CLI
  4. Testing the Oracle Cloud Infrastructure Ansible Collection
  5. Conclusion

Installing Oracle Linux 8.10 from the Windows Store

  1. Open Windows Store: Click on the Start menu and search for “Microsoft Store.”
  2. Search for Oracle Linux: In the search bar, type “Oracle Linux.”
  3. Select Oracle Linux 8.10: Click on the Oracle Linux 8.10 entry in the results.
  4. Install: Click on the “Download” button to download and install the distribution.
  5. Launch Oracle Linux: Once installed, you can launch it directly from the Windows Start menu. Enter an username and a password for the initial setup

How to install WSL: https://learn.microsoft.com/en-us/windows/wsl/install

Installing Missing OS Packages

After launching Oracle Linux for the first time, you may need to install some essential packages. Here’s how to do that. Launch the terminal.

Update the base Operating System

-- run DNF as sudo
$ sudo dnf -y update

Create the DNF repo files for Repositories OL8_Developer_EPEL and OL8_Developer.

-- DNF repo file for OL8_Developer_EPEL
$ sudo tee /etc/yum.repos.d/ol8-epel.repo<<EOF
[ol8_developer_EPEL]
name= Oracle Linux \$releasever EPEL (\$basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL8/developer/EPEL/\$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
EOF

-- DNF repo file for OL8_Developer
$ sudo tee /etc/yum.repos.d/ol8-developer.repo<<EOF
[ol8_developer]
name= Oracle Linux \$releasever Developer (\$basearch)
baseurl=https://yum.oracle.com/repo/OracleLinux/OL8/developer/\$basearch/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-oracle
gpgcheck=1
enabled=1
EOF

-- enable the repositories
$ sudo yum-config-manager --enable ol8_developer ol8_developer_EPEL

Install Oracle Cloud Infrastructure Ansible Collection packages

$ sudo yum install oci-ansible-collection

Installing and configure OCI-CLI

There are several ways to setup, authenticate and interact as developer with Oracle Cloud Infrastructure like SDK setup etc. My preferred way is the setup and configuration of the OCI-CLI. In case of troubleshooting it can be helpful to have the OCI-CLI up and running. More information about the authentication options for the Ansible collection: Authentication Guide — Oracle Cloud Infrastructure Ansible Collection 5.3.0 documentation.

In terminal as non-root OS user, execute the command to install OCI-CLI. There are no special inputs required, I use the path settings as recommended.

$ bash -c "$(curl -L https://raw.githubusercontent.com/oracle/oci-cli/master/scripts/install/install.sh)"

For the final setup, run the config command. You will need your User OCID, Tenancy OCID, and region. When prompted for the API key, generate a new one without a passphrase. The public part of the newly created API key will be used later in the Oracle Cloud Infrastructure console.

$ oci setup config

Make sure your OCI user has the appropriate IAM privileges based on the principle of least privilege to effectively interact with and manage resources in Oracle Cloud Infrastructure. Add the public key to your user as API key. Example:

$ cat /home/martinxberger/.oci/oci_api_key_public.pem
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtCvFXAd4BNZf1cPSCgAm
BmAP7ezxpwrVGNZFHIuzvssKHAawJRzgV1gujTzXjGuH0uFJivqAoRyMcJUn2kPS
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
QWZBFz2YcB5rxak4pwG0hd2QISSBX4ldQ0WhChy23ZugQiHzTZkLZokyLK99dovM
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
VpBgyqoqCRz0aMNAII8MqFRp4H428VtQODLBezcRDolOBTwNEP4J+d0CTKXaYGTR
1wIDAQAB
-----END PUBLIC KEY-----

Add the API key in OCI console, don’t forget to click on the Add button at the bottom.

Verify the setup.

-- show version
$ oci --version
3.48.1

-- get object storage namespace
$ oci os ns get
{
  "data": "<redacted>"
}

Update the Python version to avoid OCI-CLI CryptographyDeprecationWarning

To avoid this error, follow the steps here: https://www.martinberger.com/2024/04/oracle-cloud-infrastructure-cli-how-to-fix-sign-py10-cryptographydeprecationwarning/

/home/martinxberger/lib/oracle-cli/lib64/python3.6/site-packages/oci/_vendor/httpsig_cffi/sign.py:10: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.hazmat.backends import default_backend  # noqa: F401

Testing the Oracle Cloud Infrastructure Ansible Collection

When the OCI-CLI works properly, we can test the Ansible collection. A couple of test YML files are installed with the collection. This is a test to get the Object Storage namespace.

-- run the playbook
$ ansible-playbook /usr/share/doc/oci-ansible-collection/samples/object_storage/get_namespace/sample.yaml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Get namespace name] ***********************************************************************************************************

TASK [Gathering Facts] **************************************************************************************************************
ok: [localhost]

TASK [Get namespace name] ***********************************************************************************************************
ok: [localhost]

TASK [Print namespace name] *********************************************************************************************************
ok: [localhost] => {
    "msg": {
        "changed": false,
        "failed": false,
        "namespace": "<redacted>"
    }
}

PLAY RECAP ***************************************************************************************************************

Conclusion

With Oracle Linux 8.10 set up in WSL and the OCI CLI configured, using the OCI Ansible Collection has never been easier. You can now manage your Oracle Cloud resources efficiently right from your Windows environment, leveraging the powerful features of Ansible alongside the convenience of VS Code. This streamlined setup allows for quick development and deployment, making cloud management more accessible than ever. Happy automating!