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

Ansible 기초

~18 min · ansible, agentless, modules, inventory

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

Idempotent 한 자동화

Ansible 이 SSH 위 만들어진 자동화. SSH 통해 관리되는 host 에 연결하고 명령 직접 실행 — target 에 agent 소프트웨어 필요 X. Playbook(원하는 상태 묘사하는 YAML 파일) 작성하면 Ansible 이 머신을 그 상태로 수렴. Playbook 두 번 돌리면 두 번째는 이미 다 정확하면 아무것도 안 함 — 그게 idempotence, Ansible 안전하게 재실행 만드는 속성.

머릿속 모델

  • Inventory — host 목록 (이미 ~/.fleet/all.txt 에 있음).
  • Module — 빌딩 블록 — ping, command, copy, file, apt, brew, service, git 등. 각각 idempotent.
  • Playbook — multi-step 작업 묘사하는 YAML ("이 패키지 설치, 이 파일 복사, 이 서비스 재시작").

왜 셸 스크립트 대신 Ansible

셸 스크립트가 머신에게 뭐 할지 말. Playbook 이 어떤 상태일지 묘사. 첫 번째가 명령 실행; 두 번째가 상태 체크하고 필요할 때만 행동. Idempotent playbook 재실행 안전; 파일 만드는 스크립트 재실행은 중복 만들 수도, 서비스 불필요 재시작, 또는 두 번째 pass 에 실패할 수도.

Code

설치 및 임시 명령 시도·bash
# Install
brew install ansible
# or
pip install ansible

# Test connectivity to all hosts
ansible all -m ping -i ~/.fleet/all.txt

# Run an arbitrary command
ansible all -a 'uptime' -i ~/.fleet/all.txt

# Just one group (an inventory file with [groups] supports this)
ansible workstations -a 'df -h /' -i inventory.ini
Inventory 파일 형식·ini
# inventory.ini — instead of plain ~/.fleet/all.txt
[workstations]
office
server
music
worker

[laptops]
macbook
pro2024
pro2023
air

[other]
mini

[all_macs:children]
workstations
laptops
other

External links

Exercise

Ansible 설치 (brew install ansible). Fleet 전반 도달성 테스트 — ansible all -m ping -i ~/.fleet/all.txt. 모든 host 가 pong 답해야. 이제 ansible all -a 'uptime' -i ~/.fleet/all.txt. 출력 포맷팅을 bash loop 와 비교 — Ansible 의 구조화된 출력이 확장 가능하게 만드는 거.

Progress

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

댓글 0

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

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