Create always free database with the oci-ansible-modules

Beside the OCI Commandline SDK there are also ansible modules available for configuring and changing components in the Oracle Cloud.

The modules are under the GPL 3.0 license or the Apache 2.0 license and can therefore be used without any license implications, take care that creating autonomous database can cause costs in your OCI account.

https://github.com/oracle/oci-ansible-modules

For the configuration of the ansible modules there is a screencast on the git repository and the modules can also be downloaded from Ansible Galaxy A more detailed installation documentation is available on the official Ansible Documentation.

There are sample playbooks available in the repository which explains most of the available modules. The documentation for the modules are a little bit tricky to find. Documentation

After the installation and the OCI SDK configuration you can start writing your playbook for creating Always Free Autonomous Databases.

Task for creation of an Autonomous Database

The easiest Task for the creation of an autonomous always free database looks like this:

- name: Create a new Always Free Autonomous Database
  oci_autonomous_database:
    compartment_id: "{{ compartment_ocid }}"
    cpu_core_count: "{{ cpu_core_count }}"
    display_name: "{{ display_name }}"
    admin_password: "{{ admin_password }}"
    db_name: "{{ db_name }}"
    data_storage_size_in_tbs: "{{ data_storage_size_in_tbs }}"
    is_free_tier: true
    state: 'present'
  register: result

For the creation the module oci_autonomous_database is used with the corresponding parameters. A list of all available parameters can be found in the documentation (link).

The important parameter is the “is_free_tier” parameter. Unfortunately the other parameters like data_storage_size_in_tbs must be set but will be ignored if the parameter is_free_tier is set.

Output of the creation

The answer of this task will look like the following output:

{
        "failed": false,
        "autonomous_database": {
            "db_version": "18c",
            "connection_urls": {
                "machine_learning_user_management_url": "https://adb.eu-frankfurt-1.oraclecloud.com/omlusers/tenants/OMEA/databases/SID/index.html",
                "apex_url": "https://SID.adb.eu-frankfurt-1.oraclecloudapps.com/ords/apex",
                "sql_dev_web_url": "https://SID.adb.eu-frankfurt-1.oraclecloudapps.com/ords/admin/_sdw/?nav=worksheet"
            },
            "time_reclamation_of_free_autonomous_database": null,
            "is_preview": false,
            "autonomous_container_database_id": null,
            "is_auto_scaling_enabled": false,
            "is_dedicated": false,
            "is_free_tier": true,
            "time_created": "2019-12-17T13:17:11.225000+00:00",
            "db_workload": "OLTP",
            "db_name": "OOW2",
            "data_safe_status": "NOT_REGISTERED",
            "license_model": "LICENSE_INCLUDED",
            "time_maintenance_begin": "2019-12-21T09:00:00+00:00",
            "whitelisted_ips": null,
            "data_storage_size_in_tbs": 1,
            "id": "ocid1.autonomousdatabase.oc1.eu-frankfurt-1.",
            "service_console_url": "https://adb.eu-frankfurt-1.oraclecloud.com/console/index.html?tenant_name=TENANT&service_type=ATP",
            "lifecycle_state": "AVAILABLE",
            "display_name": "OOW1",
            "compartment_id": "ocid1.compartment.oc1..COMP",
            "defined_tags": {},
            "freeform_tags": {},
            "used_data_storage_size_in_tbs": null,
            "cpu_core_count": 1,
            "time_deletion_of_free_autonomous_database": null,
            "connection_strings": {
                "high": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_high.atp.oraclecloud.com",
                "all_connection_strings": {
                    "HIGH": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_high.atp.oraclecloud.com",
                    "TPURGENT": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_tpurgent.atp.oraclecloud.com",
                    "LOW": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_low.atp.oraclecloud.com",
                    "MEDIUM": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_medium.atp.oraclecloud.com",
                    "TP": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_tp.atp.oraclecloud.com"
                },
                "dedicated": null,
                "medium": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_medium.atp.oraclecloud.com",
                "low": "adb.eu-frankfurt-1.oraclecloud.com:1522/SID_low.atp.oraclecloud.com"
            },
            "lifecycle_details": null,
            "system_tags": {
                "orcl-cloud": {
                    "free-tier-retained": "true"
                }
            },
            "time_maintenance_end": "2019-12-21T13:00:00+00:00"
        },
        "changed": true
    }

In the output above we see in the block starting at line 5 the URLs for Machine Learning, Apex and for the SQL Developer Web.
The most important line is here line 15 which shows that this autonomous database is a always free database and the used settings for size and cpu during the creation of the database were ignored.
On line 24 we have the ID of this database which can be used in further steps in the playbook or in other playbooks as example for starting and stopping the database.
The connection strings for the precreated three services can be found on in the block starting in line 34.

Conclusion

With the Ansible Modules for the Oracle Cloud it is easy to create Autonomous Databases and it is easy to create always free Autonomous Databases. If an always free Autonomous Database is sufficient for your testing environment you can easily include a role in your deployment procedure for building a database and run your tests. Afterwards you can stop or delete the database and everything without costs.

From my point of view this could be a solution for minimizing the cost of a development department.

Leave a Reply

Your email address will not be published. Required fields are marked *