DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Streamlining Event Data in Event-Driven Ansible
  • Fixing Common Oracle Database Problems
  • How To Replicate Oracle Data to BigQuery With Google Cloud Datastream
  • Clean Up Event Data in Ansible Event-Driven Automation

Trending

  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Accelerating AI Inference With TensorRT
  • Why Documentation Matters More Than You Think
  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Automate Serverless Deployments With Ansible and OCI

Automate Serverless Deployments With Ansible and OCI

In this article, learn to automate serverless deployments with Ansible and OCI Functions to simplify workflows, scale apps, and reduce operational complexities.

By 
Binoj Melath Nalinakshan Nair user avatar
Binoj Melath Nalinakshan Nair
DZone Core CORE ·
Jan. 22, 25 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
3.3K Views

Join the DZone community and get the full member experience.

Join For Free

Serverless computing has become a key part of modern applications, allowing for flexible scaling, lower costs, and event-based workflows. Oracle Cloud Infrastructure (OCI) Functions is a fully managed platform that lets the user run functions on demand. It supports multiple users, scales easily, and provides serverless computing. Ansible is a powerful automation tool that makes it easier to deploy OCI Functions. It works without needing agents and uses a straightforward, declarative approach.

OCI Functions

OCI Functions is Oracle’s Function-as-a-Service (FaaS) offering, based on the open-source Fn Project. Key features of OCI Functions include:

  • Event-driven architecture: Functions can be triggered by various OCI services or HTTP requests.
  • Multi-language support: Compatible with Python, Java, Node.js, and more.
  • Containerized execution: Functions are deployed as Docker containers.
  • Seamless integration: Works natively with OCI services like Object Storage, API Gateway, and Events.

The following are the prerequisites:

  • OCI account: Oracle Cloud account with required permissions.
  • Ansible installation: Ansible installed on the deployment machine.
  • OCI CLI configuration: Configure the OCI CLI with authentication credentials (~/.oci/config). Sample config:
    YAML
     
    [DEFAULT]
    user=<USER ID>
    fingerprint=
    key_file=</path/to/key.pem>
    tenancy=<TENANCY>
    region=<REGION>
  • OCI Ansible modules: Install the OCI Ansible Collection (ansible-galaxy collection install oracle.oci)

Example Script and Demonstration

Let's take a closer look at the following sample scripts. The script below creates an OCI Function application resource using the oci_functions_application module. This module lets us manage application resources in OCI by creating, updating, or deleting them. To use it, you'll need to provide the compartment OCID, a display name, and the subnet IDs as required parameters.

YAML
 
---
- name: Create OCI Function Application
  collections:
    - oracle.oci
  hosts: localhost
  any_errors_fatal: true
  gather_facts: no
  environment:
    OCI_CONFIG_PROFILE: "<OCI PROFILE>"
    OCI_REGION: "eu-frankfurt-1"
  tasks:
     - name: Create application
       oci_functions_application:
          compartment_id: "<COMPARTMENT ID>"
          auth_type: "security_token"
          display_name: demo-app
          subnet_ids: [ "<SUBNET OCID>" ]
       register: results
    
     - name: Dump output details
       debug:
        msg: "{{ results }}"


The script below is used to create a function in OCI with the oci_functions_function module. This module allows the user to create, update, and delete function resources in OCI. To create a function, we need to provide four required parameters: display_name, application_id, image, and memory_in_mbs.

YAML
 
---
- name: Create Oracle OCI functions
  collections:
    - oracle.oci
  hosts: localhost
  any_errors_fatal: true
  gather_facts: no
  vars_files:
    - vars.yml
  environment:
    OCI_CONFIG_PROFILE: "<OCI PROFILE>"
    OCI_REGION: "eu-frankfurt-1"
  tasks:

    - name: Create function-demo
      oci_functions_function:
         display_name: function-demo
         auth_type: "security_token"
         application_id: "<APPLICATION OCID>"
         image: "fra.ocir.io/<NAESPACE>/hello-python:0.0.5"
         memory_in_mbs: 256
      register: results

    - name: Dump output details
      debug:
        msg: "{{ results }}"


The script below demonstrates how to update an existing function using the oci_functions_function module. To perform an update, we need to provide the required function_id parameter. In this example, the image parameter is also included to highlight the changes in the console and the output.

YAML
 
---
- name: Update Oracle OCI functions
  collections:
    - oracle.oci
  hosts: localhost
  any_errors_fatal: true
  gather_facts: no
  vars_files:
    - vars.yml
  environment:
    OCI_CONFIG_PROFILE: "<OCI PROFILE>"
    OCI_REGION: "eu-frankfurt-1"
  tasks:

    - name: Update function-demo
      oci_functions_function:
         function_id: "<FUNCTION OCID>"
         auth_type: "security_token"
         image: "fra.ocir.io/<NAMESPACE>/hello-python:0.0.6"
      register: results

    - name: Dump output details
      debug:
        msg: "{{ results }}"


Demo

The two screenshots below were captured after running the script to create an application. The first screenshot shows the output generated by the Ansible script, and the second one displays the application details as seen in the OCI console.

Output generated by the Ansible script


Application details as seen in the OCI console


The three screenshots below were taken after creating a function. The first screenshot shows the result of running the Ansible script, the second displays the function details in the OCI console, and the third shows the output of the fn invoke demo-app function-demo command.

Result of running the Ansible script


Function details in the OCI console


Output of the fn invoke demo-app function-demo command


The three screenshots below were captured after updating an existing function. The first shows the output from running the Ansible script to update the function, the second displays the updated details in the OCI console, and the third shows the result of the fn invoke demo-app function-demo command.

Output from running the Ansible script to update the function


Updated details in the OCI console


Result of the fn invoke demo-app function-demo command


Conclusion

Ansible provides a flexible and efficient way to deploy OCI Functions, making it easier to automate repetitive tasks and ensure consistent deployments. With its OCI-specific Ansible modules, organizations can simplify the management of serverless applications, saving developers time and effort. By integrating Ansible with OCI, operational complexities are reduced, allowing functions and related resources to be managed more efficiently.

Note: The views expressed on this blog are my own and do not necessarily reflect the views of Oracle.

Serverless computing Ansible (software) Deployment environment Oracle Database

Opinions expressed by DZone contributors are their own.

Related

  • Streamlining Event Data in Event-Driven Ansible
  • Fixing Common Oracle Database Problems
  • How To Replicate Oracle Data to BigQuery With Google Cloud Datastream
  • Clean Up Event Data in Ansible Event-Driven Automation

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!