ansible-playbook-operator

by kenchrcum

Helm chartv0.1.7App 0.1.7Verified publisher

Lightweight GitOps-focused operator for running Ansible playbooks

About this chart

Ansible Playbook Operator Helm Chart

A lightweight, GitOps-focused Kubernetes operator for executing Ansible playbooks using the Kopf framework. Built with security, observability, and operational simplicity as core principles.

Prerequisites

  • Kubernetes 1.24+
  • Helm 3.8+
  • CNI with NetworkPolicy support (optional, for NetworkPolicies)
  • Prometheus Operator (optional, for ServiceMonitor)

Installation

Basic Installation

helm install ansible-playbook-operator ./helm/ansible-playbook-operator \
  --namespace ansible-operator-system \
  --create-namespace

Custom Installation

helm install ansible-playbook-operator ./helm/ansible-playbook-operator \
  --namespace ansible-operator-system \
  --create-namespace \
  --set operator.watch.scope=all \
  --set rbac.preset=minimal \
  --set operator.metrics.enabled=true

Using Values Files

# Production deployment with image pinning
helm install ansible-playbook-operator ./helm/ansible-playbook-operator \
  --namespace ansible-operator-system \
  --create-namespace \
  --values examples/values-production-pinning.yaml

# Cluster-wide deployment
helm install ansible-playbook-operator ./helm/ansible-playbook-operator \
  --namespace ansible-operator-system \
  --create-namespace \
  --values examples/values-cluster-watch.yaml

# With NetworkPolicies enabled
helm install ansible-playbook-operator ./helm/ansible-playbook-operator \
  --namespace ansible-operator-system \
  --create-namespace \
  --values examples/values-networkpolicies.yaml

Configuration

Operator Configuration

ParameterDescriptionDefault
operator.image.repositoryOperator image repositorykenchrcum/ansible-playbook-operator
operator.image.tagOperator image tag0.1.7
operator.image.digestOperator image digest (takes precedence over tag)""
operator.image.pullPolicyImage pull policyIfNotPresent
operator.resources.requestsResource requestscpu: 100m, memory: 128Mi
operator.resources.limitsResource limitscpu: 500m, memory: 512Mi
operator.leaderElectionEnable leader electiontrue
operator.watch.scopeWatch scope (namespace or all)namespace
operator.metrics.enabledEnable Prometheus metricsfalse
operator.metrics.serviceMonitor.enabledCreate ServiceMonitortrue
operator.serviceAccount.createCreate ServiceAccounttrue
operator.serviceAccount.nameServiceAccount name""

Executor Defaults Configuration

ParameterDescriptionDefault
executorDefaults.image.repositoryExecutor image repositorykenchrcum/ansible-runner
executorDefaults.image.tagExecutor image tag13
executorDefaults.image.digestExecutor image digest (takes precedence over tag)""
executorDefaults.image.pullPolicyImage pull policyIfNotPresent
executorDefaults.serviceAccount.createCreate executor ServiceAccounttrue
executorDefaults.serviceAccount.nameExecutor ServiceAccount name""
executorDefaults.serviceAccount.rbacPresetRBAC preset (minimal, scoped, cluster-admin)minimal
executorDefaults.cache.strategyCache strategy (none, pvc)none
executorDefaults.cache.pvcNamePVC name for caching""
executorDefaults.cache.createPVCCreate PVC for cachingfalse
executorDefaults.cache.storageSizeStorage size for cache PVC10Gi
executorDefaults.cache.storageClassNameStorage class for cache PVC""

RBAC Configuration

ParameterDescriptionDefault
rbac.presetRBAC preset (minimal, scoped, cluster-admin)minimal
rbac.clusterReadEnable cluster read permissionstrue
rbac.secretRestriction.enabledEnable secret access restrictionfalse
rbac.secretRestriction.allowedSecretsList of allowed secret names[]
rbac.secretRestriction.crossNamespaceSecretsCross-namespace secret access{}

NetworkPolicy Configuration

ParameterDescriptionDefault
networkPolicies.enabledEnable NetworkPoliciesfalse
networkPolicies.presetNetworkPolicy preset (none, restrictive, moderate, permissive)none
networkPolicies.git.endpointsGit endpoints to allow[github.com, gitlab.com, bitbucket.org, gitea.com, gitee.com]
networkPolicies.git.customCustom Git endpoints[]
networkPolicies.git.portsGit ports to allow[{port: 22, protocol: TCP}, {port: 443, protocol: TCP}, {port: 80, protocol: TCP}]
networkPolicies.registries.endpointsRegistry endpoints to allow[docker.io, registry-1.docker.io, gcr.io, k8s.gcr.io, quay.io, registry.k8s.io, ghcr.io]
networkPolicies.registries.customCustom registry endpoints[]
networkPolicies.registries.portsRegistry ports to allow[{port: 443, protocol: TCP}, {port: 80, protocol: TCP}]
networkPolicies.dns.enabledEnable DNS resolutiontrue
networkPolicies.dns.endpointsDNS endpoints[10.96.0.10, 169.254.20.10]
networkPolicies.dns.portsDNS ports[{port: 53, protocol: UDP}, {port: 53, protocol: TCP}]
networkPolicies.kubernetes.enabledEnable Kubernetes API accesstrue
networkPolicies.kubernetes.endpointsKubernetes API endpoints[kubernetes.default.svc.cluster.local]
networkPolicies.kubernetes.portsKubernetes API ports[{port: 443, protocol: TCP}]
networkPolicies.additionalRulesAdditional egress rules[]

Examples

Basic Example

# Basic configuration
operator:
  image:
    repository: kenchrcum/ansible-playbook-operator
    tag: "0.1.7"
  watch:
    scope: namespace

executorDefaults:
  image:
    repository: kenchrcum/ansible-runner
    tag: 13

rbac:
  preset: minimal

Production Example

# Production configuration with security hardening
operator:
  image:
    repository: kenchrcum/ansible-playbook-operator
    tag: "0.1.7"
    digest: "sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
    pullPolicy: IfNotPresent
  resources:
    requests:
      cpu: 200m
      memory: 256Mi
    limits:
      cpu: 1000m
      memory: 1Gi
  watch:
    scope: all
  metrics:
    enabled: true
    serviceMonitor:
      enabled: true

executorDefaults:
  image:
    repository: kenchrcum/ansible-runner
    tag: 13
    digest: "sha256:abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890"
    pullPolicy: IfNotPresent
  cache:
    strategy: pvc
    createPVC: true
    storageSize: "50Gi"
    storageClassName: "fast-ssd"

rbac:
  preset: scoped
  clusterRead: true

networkPolicies:
  enabled: true
  preset: moderate

Development Example

# Development configuration with relaxed security
operator:
  image:
    repository: kenchrcum/ansible-playbook-operator
    tag: "0.1.7"
  watch:
    scope: namespace

executorDefaults:
  image:
    repository: kenchrcum/ansible-runner
    tag: 13

rbac:
  preset: minimal
  clusterRead: true

networkPolicies:
  enabled: false

RBAC Presets

Minimal (Default)

  • Scope: Single namespace
  • Permissions: Least-privilege namespaced permissions
  • Use Cases: Single-tenant deployments, development environments
  • Security Level: High

Scoped

  • Scope: Cluster-wide
  • Permissions: Cross-namespace access with controlled permissions
  • Use Cases: Centralized management, multi-tenant environments
  • Security Level: Medium

Cluster-Admin

  • Scope: Cluster-wide
  • Permissions: Full cluster permissions
  • Use Cases: Development/testing, highly trusted environments
  • Security Level: Low

NetworkPolicy Presets

None (Default)

  • Egress: All traffic allowed
  • Use Cases: Development, testing
  • Security Level: Low

Restrictive

  • Egress: Only Git endpoints and container registries
  • Use Cases: High-security environments, air-gapped deployments
  • Security Level: High

Moderate (Recommended)

  • Egress: DNS, Git endpoints, registries, and Kubernetes API
  • Use Cases: Production environments, most Ansible operations
  • Security Level: High

Permissive

  • Egress: All traffic allowed
  • Use Cases: Development, testing, troubleshooting
  • Security Level: Low

Security Considerations

Image Security

  • Use digest pinning for production deployments
  • Regularly scan images for vulnerabilities
  • Implement image signing and verification
  • Monitor for image updates and security patches

Network Security

  • Enable NetworkPolicies with appropriate presets
  • Restrict egress to only required endpoints
  • Use dedicated service accounts for different security contexts
  • Implement network segmentation

Access Control

  • Use least-privilege RBAC presets
  • Implement secret access restrictions when possible
  • Regularly audit permissions and access patterns
  • Monitor for privilege escalation attempts

Compliance

  • Maintain audit trails of all deployments
  • Document security configurations and justifications
  • Implement policy enforcement for security requirements
  • Regular security reviews and assessments

Monitoring and Observability

Metrics

  • Enable Prometheus metrics for operator monitoring
  • Use ServiceMonitor for Prometheus Operator integration
  • Monitor reconciliation counters and durations
  • Track resource usage and performance metrics

Logging

  • Structured JSON logs with correlation IDs
  • Never log secrets or sensitive information
  • Include controller, resource, and event information
  • Implement log aggregation and analysis

Events

  • Kubernetes Events for lifecycle transitions
  • Standardized event reasons across all operations
  • Event correlation with metrics and logs
  • Alerting on critical events and failures

Troubleshooting

Common Issues

1. Permission Errors

Error: forbidden: User cannot access resource

Solution: Check RBAC preset configuration and permissions

2. Network Connectivity Issues

Error: connection refused

Solution: Verify NetworkPolicy configuration and endpoints

3. Image Pull Failures

Error: failed to pull image

Solution: Check image digest, registry access, and network policies

4. Resource Quota Exceeded

Error: resource quota exceeded

Solution: Increase resource quotas or optimize resource usage

Debug Commands

# Check operator status
kubectl get deployment ansible-playbook-operator -n ansible-operator-system

# View operator logs
kubectl logs -l app.kubernetes.io/name=ansible-playbook-operator -n ansible-operator-system

# Check RBAC permissions
kubectl auth can-i get secrets --as=system:serviceaccount:ansible-operator-system:ansible-playbook-operator

# Verify NetworkPolicies
kubectl get networkpolicies -n ansible-operator-system

# Check PVC status
kubectl get pvc -n ansible-operator-system

Best Practices

1. Security

  • Use digest pinning for production deployments
  • Enable NetworkPolicies with appropriate presets
  • Implement least-privilege RBAC configurations
  • Regular security audits and updates

2. Performance

  • Configure appropriate resource requests and limits
  • Use PVC caching for frequently executed playbooks
  • Monitor resource usage and optimize as needed
  • Implement horizontal scaling if required

3. Reliability

  • Enable leader election for high availability
  • Implement proper backup and recovery procedures
  • Monitor for failures and implement alerting
  • Test disaster recovery procedures regularly

4. Operations

  • Use GitOps workflows for deployment management
  • Implement automated testing and validation
  • Maintain comprehensive documentation
  • Regular updates and maintenance procedures

Migration Guide

From Tag-Based to Digest-Based Images

  1. Get current image digests:

    crane digest kenchrcum/ansible-playbook-operator:0.1.7
    crane digest kenchrcum/ansible-runner:latest
    
  2. Update values file:

    operator:
      image:
        digest: "sha256:1234567890abcdef..."
    executorDefaults:
      image:
        digest: "sha256:abcdef1234567890..."
    
  3. Deploy and verify:

    helm upgrade ansible-playbook-operator ./helm/ansible-playbook-operator \
      --values values-image-pinning.yaml
    

From Namespace to Cluster-Wide Watch

  1. Update watch scope:

    operator:
      watch:
        scope: all
    
  2. Change RBAC preset:

    rbac:
      preset: scoped
    
  3. Deploy and test:

    helm upgrade ansible-playbook-operator ./helm/ansible-playbook-operator \
      --values values-cluster-watch.yaml
    

Support

For issues, questions, or contributions:

License

This project is licensed under the Unlicense - see the LICENSE file for details.

Deploy ansible-playbook-operator with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has ansible-playbook-operator on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartansible-playbook-operator is pinned at v0.1.7 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below
opentenant validate opentenant.yaml
terraform init && terraform apply