Skip to content

IaC & CI/CD: Build, deploy & roll back

IaC & CI/CD commands for build, deploy & roll back (tags: #deploy #build #rollback #release #compose).

Index
12 items

Terraform3

Terraform: Initialize and upgrade providers

Safe

Download modules/providers and upgrade within the version constraints.

terraform init -upgrade
What each part does
  1. terraform initset up the backend, download providers and modules
  2. -upgradepick the newest versions the constraints allow and update .terraform.lock.hcl

Also known as: tf init

Terraform: Plan and save to a file

Safe

Preview changes and save the exact plan that will be applied.

terraform plan -out=tfplan
What each part does
  1. terraform planshow what would change
  2. -out=tfplansave the plan so terraform apply tfplan does exactly that

Also known as: tf plan

Terraform: Apply a saved plan

Caution

Applies exactly what was reviewed in the saved plan. No re-plan surprises.

terraform apply tfplan
What each part does
  1. terraform applymake the changes
  2. tfplanthe saved plan file: applies exactly what was reviewed, with no new prompt

Also known as: tf apply

Ansible2

Ansible: Dry-run a playbook with diff

Safe

Shows what would change, file diffs included, without changing anything.

ansible-playbook -i <inventory> <playbook> --check --diff
What each part does
  1. ansible-playbookrun a playbook (a YAML list of plays and tasks)
  2. -i <inventory>inventory file or directory listing the hosts
  3. <playbook>the playbook file, e.g. site.yml
  4. --checkdry run: report what would change, change nothing
  5. --diffshow a before/after diff for templated and edited files

Also known as: check mode · dry run

Ansible: Run a playbook on a subset of hosts

Caution

Target one host or group, e.g. --limit web-01 or --limit 'web:!web-03'.

ansible-playbook -i <inventory> <playbook> --limit <host-pattern>
What each part does
  1. ansible-playbookrun a playbook
  2. -i <inventory>inventory file or directory
  3. <playbook>the playbook file
  4. --limit <host-pattern>only run on hosts matching the pattern, e.g. web01, webservers, 'web*:!web03'

Also known as: limit hosts · canary

Helm3

Helm: Upgrade or install a release

Safe

Idempotent deploy. --atomic rolls back automatically if the upgrade fails.

helm upgrade --install <release> <chart> -n <namespace> -f <values-file> --atomic --wait
What each part does
  1. helm upgrade --install <release>upgrade the release, or install it if it doesn't exist
  2. <chart>chart reference: repo/chart, a path, or an OCI URL
  3. -n <namespace>target namespace (add --create-namespace if it may not exist)
  4. -f <values-file>values file overriding the chart defaults
  5. --atomicroll back automatically if the upgrade fails
  6. --waitwait for pods, services etc. to be ready before reporting success

Also known as: helm upgrade · helm install

Helm: Show release history

Safe

Revisions, status and chart/app versions of a release.

helm history <release> -n <namespace>
What each part does
  1. helm history <release>every revision: number, date, status, chart and app version, description
  2. -n <namespace>namespace of the release

Also known as: helm history · another operation (install/upgrade/rollback) is in progress

Helm: Roll back a release

Caution

Return the release to an earlier revision (see helm history).

helm rollback <release> <revision> -n <namespace> --wait
What each part does
  1. helm rollback <release>redeploy a previous revision of a release (as a new revision)
  2. <revision>revision number from helm history; leave it out for the previous one
  3. -n <namespace>namespace of the release
  4. --waitwait until the resources are ready

Also known as: helm rollback

GitHub Actions1

GitHub Actions: Trigger a workflow manually

Safe

Kick off a workflow_dispatch workflow on a branch.

gh workflow run <workflow-file> --ref <branch>
What each part does
  1. gh workflow run <workflow-file>start a workflow that has a workflow_dispatch trigger, e.g. deploy.yml
  2. --ref <branch>branch or tag to run it on; pass inputs with -f name=value

Also known as: workflow_dispatch · gh workflow run

GitLab CI2

GitLab CI: Watch the pipeline for this branch

Safe

Live status of the current branch's pipeline from the terminal.

glab ci status --live
What each part does
  1. glab ci statusstatus of the latest pipeline on the current branch, job by job
  2. --livekeep refreshing until the pipeline finishes

Also known as: glab ci · pipeline status

GitLab CI: Run a pipeline on a branch

Safe

Trigger a new pipeline, e.g. to re-deploy.

glab ci run --branch <branch>
What each part does
  1. glab ci runcreate a new pipeline
  2. --branch <branch>the branch to run it on; add --variables KEY:value for CI variables

Also known as: trigger pipeline

Jenkins1

Jenkins: Trigger a parameterized build

Safe

Start a job remotely with parameters via the REST API.

curl -X POST -u <user>:<api-token> "<jenkins-url>/job/<job>/buildWithParameters?<param>=<value>"
What each part does
  1. curl -X POSTtrigger endpoints need POST
  2. -u <user>:<api-token>basic auth with an API token (no CSRF crumb needed with a token)
  3. /job/<job>/buildWithParametersqueue a build of a parameterized job
  4. ?<param>=<value>job parameters, joined with &

Also known as: jenkins api · remote build

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…