18 DevOps Automation Templates to Reuse
18 reusable DevOps templates with code: GitHub reusable workflows, GitLab components, Jenkins libraries, Terraform modules, Ansible roles, Helm and more.
The most reusable DevOps automation templates are the ones your tools already support natively: GitHub reusable workflows and composite actions, GitLab CI/CD components, Jenkins shared libraries, Azure Pipelines templates, Terraform modules, Ansible roles, Helm library charts, Kustomize bases, multi-stage Dockerfiles, project scaffolds, Backstage templates, dev containers, pre-commit configs and Renovate presets.
This guide shows eighteen of them with a minimal working skeleton for each, grouped by where they sit in the delivery flow. The focus is on the reuse mechanism (how one team writes it once and many projects consume it with a version pin), not on complete pipelines. For full pipeline examples, see 15 GitHub Actions workflows and 15 GitLab CI/CD pipeline examples.
Key takeaways
- A template is only reusable if consumers can pin a version and upgrade on their own schedule. Tag releases and use semantic versioning.
- Keep inputs few and documented. A template with 40 parameters is a second codebase nobody understands.
- Prefer the platform's native mechanism (reusable workflows, components, shared libraries, modules) over copying files between repositories.
- Put security defaults into the template (read-only tokens, pinned images, non-root containers) so every consumer gets them.
- Give every template an owner, a README with an example, and a changelog.
All 18 templates at a glance
| # | Template | Tool | How consumers pin a version |
|---|---|---|---|
| 1 | Reusable workflow | GitHub Actions | uses: org/repo/.github/workflows/x.yml@v1 |
| 2 | Composite action | GitHub Actions | uses: org/action@v1 |
| 3 | Organisation workflow templates | GitHub | Copied at creation; not versioned after |
| 4 | CI/CD component | GitLab CI | component: [email protected] |
| 5 | Shared library | Jenkins | @Library('name@v1') |
| 6 | Pipeline templates | Azure Pipelines | ref: on the repository resource |
| 7 | Terraform module | Terraform / OpenTofu | version or ?ref= in source |
| 8 | Remote state bootstrap | Terraform | Module version |
| 9 | Ansible role | Ansible | version in requirements.yml |
| 10 | Ansible collection | Ansible | Collection version |
| 11 | Helm library chart | Helm | Dependency version in Chart.yaml |
| 12 | Kustomize base and components | Kustomize | ?ref= on remote base |
| 13 | Multi-stage Dockerfile | Docker | Base image digest |
| 14 | Project scaffold | Cookiecutter / Copier | Template tag; Copier can update later |
| 15 | Software Template | Backstage | Template version in catalog |
| 16 | Dev container | Dev Containers spec | Image and feature versions |
| 17 | pre-commit config | pre-commit | rev: per hook repo |
| 18 | Renovate shared preset | Renovate | Preset reference, optionally with tag |
CI/CD pipeline templates
1. GitHub Actions reusable workflow
A reusable workflow is a complete workflow that other workflows call as a single job. It is the right choice for a whole build-test-scan sequence that every service should run the same way.
# org/ci-templates/.github/workflows/node-ci.yml
on:
workflow_call:
inputs:
node-version:
type: string
default: "22"
secrets:
NPM_TOKEN:
required: false
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
- run: npm ci
- run: npm test
# a consuming repository
jobs:
ci:
uses: org/ci-templates/.github/workflows/node-ci.yml@v1
with:
node-version: "22"
secrets: inherit
secrets: inherit passes the caller's secrets through; for tighter control, pass only the named secrets the workflow declares. See GitHub's reusing workflows documentation.
2. GitHub composite action
A composite action bundles several steps into one step. Use it for smaller units, such as "set up our toolchain and log in to the registry", that appear inside many different jobs.
# org/setup-toolchain/action.yml
name: Setup toolchain
description: Install pinned CLI tools
inputs:
terraform-version:
default: "1.9.8"
runs:
using: composite
steps:
- uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ inputs.terraform-version }}
- run: terraform version
shell: bash
Every run step in a composite action must declare a shell. The Terraform version is an example default; set the version your team supports. Reusable workflows versus composite actions in one line: reuse a job with the first, reuse steps with the second.
3. GitHub organisation workflow templates
Files placed in a workflow-templates/ folder of the organisation's public .github repository appear in the "New workflow" screen of every repository in the organisation. Each template needs a matching .properties.json file with a name and description. These are starting points: the file is copied into the repository, so later changes to the template do not reach existing repos. Pair them with reusable workflows so the copied file is a short caller rather than the full logic. Details are in creating workflow templates for your organization.
4. GitLab CI/CD component
Components are GitLab's versioned, input-validated pipeline building blocks, publishable to the CI/CD Catalog.
# templates/docker-build.yml in the component project
spec:
inputs:
image-name:
description: Image name without registry
---
docker-build:
image: docker:27
services: [docker:27-dind]
script:
- docker build -t "$CI_REGISTRY_IMAGE/$[[ inputs.image-name ]]:$CI_COMMIT_SHORT_SHA" .
- docker push "$CI_REGISTRY_IMAGE/$[[ inputs.image-name ]]:$CI_COMMIT_SHORT_SHA"
# consumer .gitlab-ci.yml
include:
- component: $CI_SERVER_FQDN/platform/components/[email protected]
inputs:
image-name: api
Our post on advanced GitLab CI/CD techniques covers components alongside extends and !reference for reuse inside one project. Reference: GitLab CI/CD components.
5. Jenkins shared library
A shared library is a Git repository of Groovy code that Jenkinsfiles load. Global steps live in vars/, and each file's call method becomes a pipeline step.
// vars/standardPipeline.groovy in the library repo
def call(Map config = [:]) {
pipeline {
agent any
stages {
stage('Build') { steps { sh "make build" } }
stage('Test') { steps { sh "make test" } }
stage('Deploy') {
when { branch 'main' }
steps { sh "./deploy.sh ${config.env ?: 'staging'}" }
}
}
}
}
// Jenkinsfile in a service repo
@Library('[email protected]') _
standardPipeline(env: 'staging')
Library code configured as a trusted global library runs outside the Groovy sandbox, so restrict who can push to it. See the Jenkins shared libraries documentation. Plugins that help here are listed in 12 Jenkins plugins that make CI/CD easier.
6. Azure Pipelines templates
Azure Pipelines can include step, job and stage templates from another repository. extends templates go further and let a platform team require that pipelines inherit from an approved template.
resources:
repositories:
- repository: templates
type: git
name: Platform/pipeline-templates
ref: refs/tags/v2.0.0
stages:
- template: stages/build-and-test.yml@templates
parameters:
dotnetVersion: "8.x"
Reference: Azure Pipelines templates.
Infrastructure templates
7. Terraform module
A module is a folder of Terraform files with input variables and outputs. Teams usually publish a small set: network, Kubernetes cluster, database, bucket with secure defaults.
# modules/s3-secure/main.tf
variable "name" { type = string }
resource "aws_s3_bucket" "this" {
bucket = var.name
}
resource "aws_s3_bucket_public_access_block" "this" {
bucket = aws_s3_bucket.this.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
resource "aws_s3_bucket_versioning" "this" {
bucket = aws_s3_bucket.this.id
versioning_configuration { status = "Enabled" }
}
output "bucket_arn" { value = aws_s3_bucket.this.arn }
# consumer
module "logs" {
source = "git::https://github.com/org/tf-modules.git//modules/s3-secure?ref=v1.3.0"
name = "acme-app-logs"
}
Modules from a registry use a separate version argument instead of ?ref=. See Terraform modules. For where Terraform sits among other IaC tools, read 12 infrastructure as code tools ranked.
8. Terraform remote state bootstrap
Every new project needs a state backend, and getting it wrong (local state, no locking, no encryption) is a common early mistake. A standard backend block plus a one-time bootstrap module removes the guesswork:
terraform {
backend "s3" {
bucket = "acme-terraform-state"
key = "apps/payments/terraform.tfstate"
region = "ap-south-1"
encrypt = true
use_lockfile = true
}
}
use_lockfile enables S3-native state locking in recent Terraform releases (it first appeared in 1.10); older setups used a DynamoDB table, and HashiCorp now marks DynamoDB-based locking as deprecated. Check the S3 backend documentation for the version you run.
9. Ansible role
Roles package tasks, handlers, templates and defaults for one job, such as "harden SSH" or "install the monitoring agent". ansible-galaxy role init creates the standard layout.
ansible-galaxy role init roles/ssh_hardening
# roles/ssh_hardening/tasks/main.yml
- name: Disable password authentication
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: '^#?PasswordAuthentication'
line: 'PasswordAuthentication no'
validate: 'sshd -t -f %s'
notify: Restart sshd
# requirements.yml in a consuming project
roles:
- name: ssh_hardening
src: https://github.com/org/ansible-role-ssh-hardening.git
scm: git
version: v1.1.0
The validate line runs sshd -t against the new file before replacing the real one, so a typo cannot lock you out. More production examples are in top 15 Ansible playbooks used in production.
10. Ansible collection
When a team owns several roles, modules and plugins, a collection packages them under one namespace and version (for example acme.platform). Consumers install it with ansible-galaxy collection install from a Git URL, a tarball, Ansible Galaxy or a private Automation Hub. See using Ansible collections.
Kubernetes and container templates
11. Helm library chart
A library chart (type: library in Chart.yaml) contains only named templates and cannot be installed on its own. Application charts depend on it and call its templates, so labels, probes and security contexts stay identical across services.
# Chart.yaml of an application chart
apiVersion: v2
name: payments
version: 0.4.0
dependencies:
- name: common-lib
version: 1.2.0
repository: oci://registry.example.com/charts
# templates/deployment.yaml
{{ include "common-lib.deployment" . }}
See the Helm library charts documentation and our 10 Helm chart examples.
12. Kustomize base, overlays and components
A base holds shared manifests; overlays patch them per environment. Components (kind: Component) are optional feature bundles, such as "add a Prometheus ServiceMonitor", that any overlay can switch on.
# overlays/prod/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- https://github.com/org/k8s-bases//web?ref=v2.1.0
components:
- ../../components/monitoring
patches:
- target:
kind: Deployment
name: web
patch: |-
- op: replace
path: /spec/replicas
value: 4
Reference: Kustomize components. Our YAML essentials for Kubernetes post helps if the indentation rules trip you up.
13. Multi-stage Dockerfile
A standard multi-stage Dockerfile per language keeps build tools out of the runtime image and runs as a non-root user.
# syntax=docker/dockerfile:1
FROM golang:1.23 AS build
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o /out/app ./cmd/app
FROM gcr.io/distroless/static-debian12:nonroot
COPY --from=build /out/app /app
USER nonroot
ENTRYPOINT ["/app"]
Copying dependency files before the source lets Docker cache the download layer. Pin base images by digest in production. See Docker multi-stage builds.
Project and developer templates
14. Cookiecutter or Copier project scaffold
A scaffold generates a new repository with the folder layout, CI caller workflow, Dockerfile, README and CODEOWNERS already in place. Cookiecutter generates once. Copier can also apply later template changes to projects created from it with copier update, which helps keep old repositories aligned.
copier copy gh:org/service-template ./payments-api
# later, pull in template improvements
cd payments-api && copier update
15. Backstage Software Template
If your organisation runs Backstage, its scaffolder turns a template into a form in the developer portal. A developer fills in a name and owner, and the template creates the repository, registers it in the catalog and can open the first pull request.
apiVersion: scaffolder.backstage.io/v1beta3
kind: Template
metadata:
name: node-service
title: Node.js service
spec:
owner: platform-team
type: service
parameters:
- title: Service details
required: [name]
properties:
name:
type: string
steps:
- id: fetch
name: Fetch skeleton
action: fetch:template
input:
url: ./skeleton
values:
name: ${{ parameters.name }}
- id: publish
name: Publish
action: publish:github
input:
repoUrl: github.com?owner=org&repo=${{ parameters.name }}
See Backstage Software Templates.
16. Dev container definition
A .devcontainer/devcontainer.json file describes a development environment that VS Code, GitHub Codespaces and other supporting tools can build, so every engineer gets the same CLI versions.
{
"name": "platform-tools",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/terraform:1": {},
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {}
},
"postCreateCommand": "pre-commit install"
}
Reference: Development Containers specification.
17. pre-commit configuration
A shared .pre-commit-config.yaml runs formatters, linters and secret detection before code leaves the laptop. Run the same hooks in CI so nobody can skip them.
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-yaml
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.96.1
hooks:
- id: terraform_fmt
- repo: https://github.com/gitleaks/gitleaks
rev: v8.21.2
hooks:
- id: gitleaks
pre-commit autoupdate bumps the rev values. The versions shown are examples; run autoupdate to get current ones. See pre-commit.com.
18. Renovate shared preset
A shared Renovate preset keeps dependency update rules consistent: schedules, grouping, automerge for patch updates, and SHA pinning for GitHub Actions. Each repository's config then becomes one line.
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["github>org/renovate-config"]
}
The preset repository holds a default.json that can itself extend config:recommended and add organisation rules. See Renovate shareable config presets.
How to run a template library
- Start from repetition. Only template something three or more teams already do by hand.
- Version everything. Tag releases, follow semantic versioning, and never move a tag.
- Test templates. Run each template against a sample project in its own CI before releasing.
- Document with examples. A README with a copy-paste consumer example beats a parameter table.
- Automate upgrades. Let Renovate or Dependabot raise pull requests when a new template version ships.
- Allow escape hatches. Teams with unusual needs should be able to override or skip a step without forking the whole template.
Common mistakes
- Consumers pinned to
@main, so one bad merge to the template breaks every pipeline at once. - Templates that hard-code secrets, account IDs or regions instead of taking them as inputs.
- Copy-paste "templates" that drift the day after they are copied.
- Too many layers of templates calling templates, so nobody can tell what a pipeline actually runs.
- No owner, so the template rots until teams quietly stop using it.
Terraform modules and Ansible roles are taught hands-on in our Terraform training and Ansible training, available in the Kharadi, Pune classroom and live online.
Frequently asked questions
What is a DevOps automation template?
It is a reusable, versioned piece of automation, such as a pipeline workflow, Terraform module, Ansible role or Helm chart, that many projects consume instead of writing the same logic themselves.
What is the difference between a reusable workflow and a composite action?
A reusable workflow is called as a whole job and can contain several jobs of its own. A composite action packages a set of steps that run inside a job. Use reusable workflows for full pipelines and composite actions for repeated step groups.
How should teams version shared templates?
Tag releases with semantic versions, have consumers pin a tag or commit SHA rather than a branch, and use Renovate or Dependabot to propose upgrades. Never move an existing tag.
Are GitHub organisation workflow templates updated in existing repositories?
No. They are copied into a repository when someone creates a workflow from them. To push changes centrally, make the template a short file that calls a reusable workflow.
What is a Helm library chart?
It is a chart with type: library that contains only named templates. Application charts list it as a dependency and include its templates, which keeps common manifests consistent across services.
Should I use Cookiecutter or Copier?
Both generate projects from a template. Copier can also apply later template updates to existing projects with copier update, which suits long-lived service templates. Cookiecutter generates once.
How many inputs should a template have?
As few as possible. Cover the common case with sensible defaults and a handful of documented inputs, and let unusual projects override specific steps instead of adding a parameter for every variation.
Where should Terraform state be stored for templated projects?
In a remote backend with encryption and locking, such as S3 with use_lockfile = true on a recent Terraform release. A standard backend block in your project scaffold prevents local state files.
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0