This section will give a brief overview of the Ansible Operator with a step-by-step example of developing an Ansible Operator using Operator SDK.
The reader is expected to have a basic understanding of the Operator pattern.
- Ansible Operator is an Operator which is powered by Ansible.
- Custom Resource events trigger Ansible tasks as opposed to the traditional approach of handling these events with Go code.
Ansible Operator development and testing is fully supported as a first-class citizen within the Operator SDK. Operator SDK can be used to create new Operator projects, test existing Operator projects, build Operator images, and generate new Custom Resource Definitions (CRDs) for an Operator.
By the end of this section the reader should have a basic understanding of:
- What the Ansible Operator is
- How the Ansible Operator maps Custom Resource events to Ansible code
- How to pass extra variables to Ansible code via the operator
- How to leverage existing roles from Ansible Galaxy
- How to deploy and run the Ansible Operator in a OpenShift cluster
- How to run the Ansible Operator Locally for development
Thank you for taking a closer look at the Ansible Operator. For more Information, check out the links below:
- Operator-Framework: https://github.com/operator-framework
- Operator-SDK: https://sdk.operatorframework.io/docs/building-operators/ansible/
- Memcached Ansible Operator Demo: https://www.youtube.com/watch?v=Smk9oQp7YMY
- OpenShift Commons Briefing Ansible Operator - Operator Framework SIG: https://www.youtube.com/watch?v=YFTQJI6foGc
- Sample Operators using Ansible: https://github.com/operator-framework/operator-sdk-samples/tree/master/ansible
- Kubernetes Slack Chat (upstream): #kubernetes-operators at https://kubernetes.slack.com/
- Operator-Framework on Google Groups: https://groups.google.com/forum/#!forum/operator-framework
- OpenShift Operators Special Interest Group (SIG): https://commons.openshift.org/sig/OpenshiftOperators.html
Ansible Operator Overview
The Ansible Operator
This step doesn't require changes to the interactive environment, but feel free to explore.
Why an Operator?
Operators make it easy to manage complex stateful applications on top of Kubernetes. However writing an operator today can be difficult because of challenges such as using low level APIs, writing boilerplate, and a lack of modularity which leads to duplication.
The Operator SDK is a framework that uses the controller-runtime library to make writing operators easier by providing:
- High level APIs and abstractions to write the operational logic more intuitively
- Tools for scaffolding and code generation to bootstrap a new project fast
- Extensions to cover common operator use cases
What is an Ansible Operator?
A collection of building blocks from Operator SDK that enables Ansible to handle the reconciliation logic for an Operator.
Included in Operator Framework
Ansible Operator is one of the available types of Operators that Operator SDK is able to generate. Operator SDK can create an operator using Golang, Helm, or Ansible.
How do I use it?
Build your Ansible code on top of a provided base image along with some metadata to map Kubernetes events to Ansible Playbooks or Roles.
The following workflow is for a new Ansible operator:
- Create a new Operator project using the Operator SDK Command Line Interface (CLI)
- Write the reconciling logic for your object using Ansible Playbooks and Roles
- Use the SDK CLI to build and generate the operator deployment manifests
- Optionally add additional CRD's using the SDK CLI and repeat steps 2 and 3
Now, let's dig into the specifics and walk through an example.