Summary
Install Virtual Environment
Run the following commands to create a Python virtual environment, called oci-ansible
:
mkdir -p ~/.venv cd ~/.venv python3 -m venv oci-ansible
Create Shell Function
The shell function, activate
, is used several times in this procedure. Its definition is:
activate () { [[ $# -eq 0 ]] && return 1; [[ ! -d ~/.venv/$1/bin ]] && return 1; source ~/.venv/$1/bin/activate; return 0 }
Install OCI Ansible
Run the following commands to install OCI Ansible environment in the virtual environment:
cd activate oci-ansible pip3 install oci ansible
The sample output is:
Collecting oci Using cached oci-2.141.1-py3-none-any.whl.metadata (5.3 kB) Collecting ansible Downloading ansible-11.1.0-py3-none-any.whl.metadata (8.0 kB) Collecting certifi (from oci) Using cached certifi-2024.12.14-py3-none-any.whl.metadata (2.3 kB) Collecting cryptography<46.0.0,>=3.2.1 (from oci) Using cached cryptography-44.0.0-cp39-abi3-manylinux_2_28_x86_64.whl.metadata (5.7 kB) Collecting pyOpenSSL<25.0.0,>=17.5.0 (from oci) Using cached pyOpenSSL-24.3.0-py3-none-any.whl.metadata (15 kB) Collecting python-dateutil<3.0.0,>=2.5.3 (from oci) Using cached python_dateutil-2.9.0.post0-py2.py3-none-any.whl.metadata (8.4 kB) Collecting pytz>=2016.10 (from oci) Using cached pytz-2024.2-py2.py3-none-any.whl.metadata (22 kB) Collecting circuitbreaker<3.0.0,>=1.3.1 (from oci) Using cached circuitbreaker-2.0.0-py2.py3-none-any.whl.metadata (7.7 kB) Collecting ansible-core~=2.18.1 (from ansible) Downloading ansible_core-2.18.1-py3-none-any.whl.metadata (7.7 kB) Collecting jinja2>=3.0.0 (from ansible-core~=2.18.1->ansible) Downloading jinja2-3.1.5-py3-none-any.whl.metadata (2.6 kB) Collecting PyYAML>=5.1 (from ansible-core~=2.18.1->ansible) Downloading PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (2.1 kB) Collecting packaging (from ansible-core~=2.18.1->ansible) Downloading packaging-24.2-py3-none-any.whl.metadata (3.2 kB) Collecting resolvelib<1.1.0,>=0.5.3 (from ansible-core~=2.18.1->ansible) Downloading resolvelib-1.0.1-py2.py3-none-any.whl.metadata (4.0 kB) Collecting cffi>=1.12 (from cryptography<46.0.0,>=3.2.1->oci) Using cached cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.5 kB) Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.5.3->oci) Using cached six-1.17.0-py2.py3-none-any.whl.metadata (1.7 kB) Collecting pycparser (from cffi>=1.12->cryptography<46.0.0,>=3.2.1->oci) Using cached pycparser-2.22-py3-none-any.whl.metadata (943 bytes) Collecting MarkupSafe>=2.0 (from jinja2>=3.0.0->ansible-core~=2.18.1->ansible) Downloading MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.0 kB) Using cached oci-2.141.1-py3-none-any.whl (28.6 MB) Downloading ansible-11.1.0-py3-none-any.whl (51.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 51.4/51.4 MB 4.2 MB/s eta 0:00:00 Downloading ansible_core-2.18.1-py3-none-any.whl (2.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 MB 3.0 MB/s eta 0:00:00 Using cached circuitbreaker-2.0.0-py2.py3-none-any.whl (7.6 kB) Using cached cryptography-44.0.0-cp39-abi3-manylinux_2_28_x86_64.whl (4.2 MB) Using cached pyOpenSSL-24.3.0-py3-none-any.whl (56 kB) Using cached python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB) Using cached pytz-2024.2-py2.py3-none-any.whl (508 kB) Using cached certifi-2024.12.14-py3-none-any.whl (164 kB) Using cached cffi-1.17.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (479 kB) Downloading jinja2-3.1.5-py3-none-any.whl (134 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 134.6/134.6 kB 2.8 MB/s eta 0:00:00 Downloading PyYAML-6.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (767 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 767.5/767.5 kB 5.0 MB/s eta 0:00:00 Downloading resolvelib-1.0.1-py2.py3-none-any.whl (17 kB) Using cached six-1.17.0-py2.py3-none-any.whl (11 kB) Downloading packaging-24.2-py3-none-any.whl (65 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.5/65.5 kB 1.5 MB/s eta 0:00:00 Downloading MarkupSafe-3.0.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23 kB) Using cached pycparser-2.22-py3-none-any.whl (117 kB) Installing collected packages: resolvelib, pytz, circuitbreaker, six, PyYAML, pycparser, packaging, MarkupSafe, certifi, python-dateutil, jinja2, cffi, cryptography, pyOpenSSL, ansible-core, oci, ansible Successfully installed MarkupSafe-3.0.2 PyYAML-6.0.2 ansible-11.1.0 ansible-core-2.18.1 certifi-2024.12.14 cffi-1.17.1 circuitbreaker-2.0.0 cryptography-44.0.0 jinja2-3.1.5 oci-2.141.1 packaging-24.2 pyOpenSSL-24.3.0 pycparser-2.22 python-dateutil-2.9.0.post0 pytz-2024.2 resolvelib-1.0.1 six-1.17.0
Download and install OCI Ansible modules:
ansible-galaxy collection install -f oracle.oci
Sample output is:
Starting galaxy collection install process Process install dependency map Starting collection install process Downloading https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/oracle-oci-5.3.0.tar.gz to /home/mylearn/.ansible/tmp/ansible-local-12202k7hbuif2/tmpc9r0zqa6/oracle-oci-5.3.0-8p7c875y Installing 'oracle.oci:5.3.0' to '/home/mylearn/.ansible/collections/ansible_collections/oracle/oci' oracle.oci:5.3.0 was installed successfully
Test Installation
Run the following commands to test installation:
activate oci-ansible ansible localhost -m oracle.oci.oci_object_storage_namespace_facts
The sample output is:
[WARNING]: No inventory was parsed, only implicit localhost is available localhost | SUCCESS => { "changed": false, "namespace": "sdorfvwhnhvj" }