AgentStack
SKILL verified MIT Self-run

Ansible Playbooks

skill-sawrus-agent-guides-ansible-playbooks · by sawrus

Write idempotent Ansible playbooks and roles for server configuration, K8s node provisioning, and application bootstrap.

No reviews yet
0 installs
16 views
0.0% view→install

Install

$ agentstack add skill-sawrus-agent-guides-ansible-playbooks

✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access Used
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

Are you the author of Ansible Playbooks? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Skill: Ansible Playbooks

> Expertise: Idempotent roles, inventory patterns, Vault integration, molecule testing, bare-metal K8s node prep.

When to load

When configuring bare-metal servers, provisioning K8s nodes, managing OS-level config, or rotating OS credentials.

Role Structure (Standard)

roles/base-server/
├── tasks/
│   ├── main.yml         ← imports sub-task files
│   ├── packages.yml
│   ├── sysctl.yml
│   └── users.yml
├── defaults/
│   └── main.yml         ← all variables with sensible defaults
├── vars/
│   └── main.yml         ← internal constants (not overridable)
├── templates/
│   └── sysctl.conf.j2
├── handlers/
│   └── main.yml         ← restart services on change
└── meta/
    └── main.yml         ← role dependencies

Idempotency Patterns

# ✅ Package install — idempotent
- name: Install required packages
  ansible.builtin.apt:
    name:
      - containerd
      - curl
      - jq
    state: present
    update_cache: true
  when: ansible_os_family == "Debian"

# ✅ File with checksum validation — only copies if changed
- name: Configure containerd
  ansible.builtin.template:
    src: containerd-config.toml.j2
    dest: /etc/containerd/config.toml
    owner: root
    group: root
    mode: "0644"
  notify: Restart containerd     # handler only fires if file changed

# ✅ Service management
- name: Enable and start containerd
  ansible.builtin.systemd:
    name: containerd
    enabled: true
    state: started
    daemon_reload: true

Handlers Pattern

# handlers/main.yml
- name: Restart containerd
  ansible.builtin.systemd:
    name: containerd
    state: restarted

- name: Reload sysctl
  ansible.builtin.command: sysctl --system
  changed_when: false

Inventory Structure

# inventory/production/hosts.ini
[control_plane]
cp-01 ansible_host=192.168.10.10
cp-02 ansible_host=192.168.10.11
cp-03 ansible_host=192.168.10.12

[workers]
worker-01 ansible_host=192.168.10.20
worker-02 ansible_host=192.168.10.21

[k8s_cluster:children]
control_plane
workers

[k8s_cluster:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=~/.ssh/infra-key
ansible_python_interpreter=/usr/bin/python3

Vault for Secrets

# Encrypt a vars file
ansible-vault encrypt group_vars/all/vault.yml

# Inline encrypted variable
ansible-vault encrypt_string 'supersecretpassword' --name 'db_password'
# group_vars/all/vault.yml (encrypted)
vault_db_password: !vault |
  $ANSIBLE_VAULT;1.1;AES256
  ...

# group_vars/all/vars.yml (plain, references vault vars)
db_password: "{{ vault_db_password }}"

K8s Node Prep Playbook (bare-metal)

# playbooks/k8s-node-prep.yml
---
- name: Prepare K8s nodes
  hosts: k8s_cluster
  become: true
  roles:
    - role: base-server          # OS hardening, packages
    - role: k8s-prereqs          # swap off, kernel modules, sysctl
    - role: containerd           # install + configure containerd
    - role: kubeadm-install      # install kubeadm, kubelet, kubectl (pinned)

Running Playbooks

# Dry run (check mode)
ansible-playbook -i inventory/production/hosts.ini \
  playbooks/k8s-node-prep.yml --check --diff

# Run with vault password
ansible-playbook -i inventory/production/hosts.ini \
  playbooks/k8s-node-prep.yml \
  --vault-password-file ~/.ansible-vault-password

# Limit to specific hosts
ansible-playbook -i inventory/production/hosts.ini \
  playbooks/k8s-node-prep.yml \
  --limit "worker-01,worker-02"

# Tags for partial runs
ansible-playbook ... --tags "packages,sysctl" --skip-tags "users"

Lint & Test

# Lint (enforce best practices)
ansible-lint playbooks/k8s-node-prep.yml

# Molecule test (spins container, runs playbook, verifies)
cd roles/base-server && molecule test

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet — be the first.

Versions

  • v0.1.0 Imported from the upstream source.