DevOps and Infrastructure as Code MOC
Hub for managing infrastructure from code, writing automation that can run twice, shipping and versioning software, and seeing what it does in production.
Core concepts
Infrastructure as Code
- Declarative Tools Converge on a Desired State, Imperative Scripts Replay Steps: imperative "how" vs declarative "what", and why IaC beats console clicks.
- Idempotent Scripts Check the Current State Before Changing It:
sedreplacement instead of>>, state checks,set -euo pipefailand expected failures. - Terraform Plans Changes by Comparing Code with Its State File:
init/plan/apply, what state stores, protecting it, and forced replacements. - Post-Deploy Automation Must Treat Already Configured as Success: Python and REST APIs to configure apps after pods start, without
shell=True. - GitOps Agents Pull the Desired State from Git and Revert Changes Made Outside It: Git as the desired state, an in-cluster agent pulling and reconciling, rollbacks by revert.
- Argo CD Can Adopt a Running Helm Release When It Renders the Same Chart, Values and Release Name: taking over a hand-installed Helm release without restarting it.
- In an App of Apps, Only the Root Is Applied by Hand, So Its Sync Policy Decides What a Commit Can Delete: the app-of-apps root and what its sync policy lets a commit delete.
- Move Files an Application Tracks Through Its API, Because Its Database Records Their Paths: an app's database records file paths; relocate through its API or rescan after moving.
Ansible
- Inventory ansible_user Overrides a Play's remote_user: variables beat playbook keywords; a misleading
aptlock error. - Ansible become_method su Runs a Non-Login Shell Without sbin in PATH:
suvssu -, absolute paths forvisudoand othersbintools. - Ansible Handlers Notified in a Failed Run Never Fire, and the Re-run Sees Nothing to Change: the in-memory handler queue, lost restarts after a failure,
--force-handlers,flush_handlers. - Ansible Reports Every command and shell Task as Changed Unless creates or changed_when Decides:
creates/removes,changed_whenfrom a checksum, conditions that silence handlers. - An Ansible replace Task That Matches Nothing Reports ok, So Assert the End State:
okas "nothing to do", content-based preconditions, assertion tasks.
Delivery & versioning
- Semantic Versioning Signals Breaking Changes Through the Major Number:
MAJOR.MINOR.PATCH, caret and tilde ranges, lockfiles. - The Lindy Effect Favors Technologies That Have Already Lasted: using a tool's track record to choose a long-lived stack.
Observability
- Distributed Tracing Follows a Request Across Services by Propagating a Trace Context: spans, traces,
traceparent, OpenTelemetry. - Monitoring Observes State, Event Management Decides Which Changes Need Action: informational, warning and exception events, and routing each class differently.
Reference (05 - SOPs & Manuals/)
- Jenkins Cheat Sheet: jobs, builds, triggers, pipelines; running Jenkins in Docker or as a service.
- Git Cheat Sheet: remotes, history, branches and forcing SSH.
- Ansible CLI Cheat Sheet: ad hoc commands,
-b -K -k,ansible.cfgtemp directories, async fire-and-forget, secrets without prompts. - Bash Scripting Cheat Sheet: strict mode, heredocs, wrappers, traps and macOS Bash 3.2.
Post-mortems (06 - Posts/)
- Specify the versions of the softwares you install on your server: an unpinned package in Terraform
user_data. - Embracing the False Positive: Handling SSH Drops in Ansible: when automation fails because it succeeded.
- The Playbook That Said ok: when automation succeeds because it did nothing.
Related maps
- Kubernetes MOC: the declarative platform most of this automation targets.
- Cloud Computing MOC: the resources Terraform provisions.
- Linux Administration MOC: the hosts the scripts configure.
References
- The Twelve-Factor App - principles for apps that deploy cleanly from code.