Skip to content

IaC & CI/CD: Debug & troubleshoot

IaC & CI/CD commands for debug & troubleshoot (tags: #debug #performance).

Index
13 items

Terraform3

Terraform: Inspect state for a resource

Safe

All attributes Terraform has recorded for one resource.

terraform state show <resource-address>
What each part does
  1. terraform state showprint every attribute Terraform has stored for one resource
  2. <resource-address>e.g. aws_instance.web or module.vpc.aws_subnet.private[0] (see terraform state list)
Example
$ terraform state show 'module.vpc.aws_subnet.private[0]'

Also known as: tf state show · terraform state list

Terraform: Release a stuck state lock

Destructive

Removes a lock left behind by a crashed run. Make sure nothing else is running first.

terraform force-unlock <lock-id>
What each part does
  1. terraform force-unlockremove a state lock left by a crashed or killed run
  2. <lock-id>the ID shown in the Error acquiring the state lock message; make sure no one else is running

My note The lock ID is in the error message. See the gotcha on state locks.

Also known as: Error acquiring the state lock · state lock · ConditionalCheckFailedException · tf lock

Terraform: Enable debug logging

Safe

Write provider/API level debug logs to a file.

TF_LOG=DEBUG TF_LOG_PATH=./tf-debug.log terraform plan
What each part does
  1. TF_LOG=DEBUGlog level for this run: TRACE, DEBUG, INFO, WARN, ERROR
  2. TF_LOG_PATH=./tf-debug.logwrite the log to a file instead of stderr
  3. terraform planthe command to debug

Also known as: TF_LOG · tf debug

Ansible4

Ansible: Ping all hosts in an inventory

Safe

Checks SSH connectivity and Python on every host (not ICMP ping).

ansible all -i <inventory> -m ping
What each part does
  1. ansiblerun a single ad-hoc module (no playbook)
  2. allhost pattern: every host in the inventory
  3. -i <inventory>inventory file or directory
  4. -m pingthe ping module: checks SSH login + Python on the host (not ICMP); success prints pong

Also known as: UNREACHABLE · ansible ping

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 an ad-hoc command as root

Caution

Quick one-off command on many hosts with privilege escalation.

ansible <host-pattern> -i <inventory> -b -m shell -a "<command>"
What each part does
  1. ansible <host-pattern>run an ad-hoc module against matching hosts
  2. -i <inventory>inventory file or directory
  3. -bbecome: escalate privileges (sudo to root by default)
  4. -m shellshell module: runs through /bin/sh, so pipes and redirects work
  5. -a "<command>"the module arguments: the command line to run
Example
$ ansible web -i inventory/prod -b -m shell -a "df -h /"

Also known as: ad-hoc · ansible shell

Ansible: Show facts for a host

Safe

Gathered facts (OS, IPs, mounts…). Filter with a glob like ansible_distribution*.

ansible <host> -i <inventory> -m setup -a "filter=<fact-filter>"
What each part does
  1. ansible <host>run an ad-hoc module on one host (or pattern)
  2. -i <inventory>inventory file or directory
  3. -m setupsetup module: gathers the facts Ansible knows about the host
  4. -a "filter=<fact-filter>"only return matching facts, e.g. ansible_distribution* or ansible_default_ipv4

Also known as: ansible facts · setup module

Helm1

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

GitHub Actions1

GitHub Actions: Show logs of failed steps

Safe

Only the log output of failed steps. gh run list shows recent run ids.

gh run view <run-id> --log-failed
What each part does
  1. gh run view <run-id>show a workflow run (gh run list gives the IDs)
  2. --log-failedprint only the logs of the failed steps

Also known as: gha logs · workflow failed · gh run view

GitLab CI3

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: Show a job's log

Safe

Stream the log of a CI job (pick interactively if you omit the id).

glab ci trace <job-id>
What each part does
  1. glab ci tracestream a CI job's log (follows it while running)
  2. <job-id>the job ID; leave it out to pick a job interactively

Also known as: job log · glab trace

GitLab CI: Lint .gitlab-ci.yml

Safe

Validate the CI config against the GitLab instance before pushing.

glab ci lint
What each part does
  1. glab ci lintsend .gitlab-ci.yml to the GitLab CI lint API and report syntax / config errors

Also known as: yaml invalid · ci lint

Jenkins1

Jenkins: Tail a build's console log

Safe

Last 100 lines of the latest build's console without opening the UI.

curl -sS -u <user>:<api-token> "<jenkins-url>/job/<job>/lastBuild/consoleText" | tail -n 100
What each part does
  1. curl -sSquiet, but still show errors
  2. -u <user>:<api-token>basic auth with a Jenkins API token
  3. /job/<job>/lastBuild/consoleTextplain-text console output of the latest build (use a build number instead of lastBuild)
  4. | tail -n 100only the last 100 lines

Also known as: jenkins console · build log

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/…