OCI: Ansible setup for OCI on OL6.9

Relevant document is here and here.

Not that Ansible needs Python 2.7+.


How to install (root)

Install should probably be along these lines on OL6.x. It is better to install in such a way that it can cohabit with multiple python versions.

yum install python27 python33 git
alternatives --install /usr/bin/python python /usr/bin/python2.7 2
alternatives --install /usr/bin/python python /usr/bin/python3.3 1
scl enable python27 bash
pip2 install oci
pip2 install ansible
git clone https://github.com/oracle/oci-ansible-modules.git
cd oci-ansible-modules


Sample usage

#1 Switch to the python27 context

scl enable python2.7 bash


#2 Configure the file $HOME/.oci/config with a similar content



#3 Configure a sample list_buckets.yml file with a similar content:

- name : List summary of existing buckets in OCI object storage
 connection: local
 hosts: localhost
 - name: List bucket facts
 namespace_name: '<tenant>'
 compartment_id: 'ocid1.tenancy.oc1..xxxx'
 register: result
 - name: Dump result
 msg: '{{result}}'


#4 Execute the script

ansible-playbook list_buckets.yml

[WARNING]: Unable to parse /etc/ansible/hosts as an inventory source

[WARNING]: No inventory was parsed, only implicit localhost is available

[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [List summary of existing buckets in OCI object storage] **************************************************************************************************

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

TASK [List bucket facts] ***************************************************************************************************************************************
ok: [localhost]

TASK [Dump result] *********************************************************************************************************************************************
ok: [localhost] => {
 "msg": {
 "buckets": [
 "compartment_id": "xxxxx", 
 "created_by": "xxxxx", 
 "defined_tags": null, 
 "etag": "xxxxx", 
 "freeform_tags": null, 
 "name": "xxx", 
 "namespace": "xxxx", 
 "time_created": "xxxx"
 "changed": false, 
 "failed": false

PLAY RECAP *****************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s