C.W.K.
Stream
Lesson 07 of 14 · published

Ansible Playbook 예

~18 min · ansible, playbook, yaml, tasks

Level 0Pinger
0 XP0/101 lessons0/12 achievements
0/150 XP to next level150 XP to go0% complete

임시에서 반복 가능으로

임시 ansible all -a 'cmd' 가 parallel-ssh 사용 사례. Playbook 이 Ansible 이 자기 값 하는 곳 — 머신을 원하는 상태로 idempotent 하게 수렴하는 multi-step workflow.

Playbook 의 해부

YAML 파일 — play (target host + task), task (각각 module 호출), 옵션으로 등록된 출력 (register:) 을 when: 으로 분기. Module 이 빌딩 블록; orchestration 이 합성.

Code

update-all.yml — daily fleet 업데이트·yaml
---
- name: Update all Macs
  hosts: all_macs
  tasks:
    - name: brew update
      command: brew update
      register: update_result
      changed_when: "'Already up-to-date' not in update_result.stdout"

    - name: brew upgrade
      command: brew upgrade
      register: upgrade_result

    - name: Show upgraded packages
      debug:
        var: upgrade_result.stdout_lines
      when: upgrade_result.stdout_lines | length > 0

    - name: Cleanup old versions
      command: brew cleanup -s

    - name: Disk space report
      command: df -h /
      register: disk_info
      changed_when: false

    - name: Show disk space
      debug:
        msg: "{{ inventory_hostname }}: {{ disk_info.stdout_lines[-1] }}"
Playbook 실행·bash
# Standard run
ansible-playbook update-all.yml -i inventory.ini

# Dry run (check mode)
ansible-playbook update-all.yml -i inventory.ini --check

# Limit to specific hosts
ansible-playbook update-all.yml -i inventory.ini --limit office,server

# Verbose
ansible-playbook update-all.yml -i inventory.ini -v

External links

Exercise

예제 playbook 을 update-all.yml 로 저장. Dry-run 먼저 — ansible-playbook update-all.yml -i inventory.ini --check --limit office. 맞아 보이면 한 host 에 실제 실행. 자신 있으면 all_macs 에. 머신마다 수동 SSH 와 경험 비교 — 그게 회수한 시간.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.