1. Ansible 모듈
- 관리할 대상 서버에 수행할 작업을 정의한 작은 코드 단위
- 목적
- 다양한 작업 자동화
- 시스템 관리
- 애플리케이션 배포
- 클라우드 서비스 관리
1.1 Ansible 모듈 종류
- 기본 모듈
- file, copy, yum, apt, service
- 클라우드 모듈
- ec2, s3
- gcp_compute_instance : Google Cloud
- 네트워크 모듈
- ios_config, nxos_config : Cisco 장비의 설정 변경
- junos_config : Juniper 장비 관리
- DB 모듈
- mysql_db
- postgresql_user : PostgreSQL 사용자 관리
1.2 실습
- 모든 호스트 그룹에 ping 날리기

ansible all -m ping
- 만약에 없는 IP 를 넣는다면?


1.2.1 sh 전송
ansible all -m shell -a "echo \"hello world\""

- 서버의 상태를 확인할 수 있는
free -h명령 날리기
ansible all -m shell -a "free -h"

1.2.2 파일 전송
- target 인스턴스에서
mkdir tmp
- master 인스턴스에서
echo "hello ansible" >> hello.txt
cat hello.txt
ansible all -m copy -a "src=./hello.txt dest=/home/ubuntu/tmp"


잘 들어왔다~
1.2.3 패키지 모듈 전송
- target 인스턴스에서 nano 에디터를 지워보자.
sudo apt remove nano
nano

- master 인스턴스에서 원격으로 설치하기
ansible target -m apt -a "name=nano state=present" --become

→ 48에서만 지웠기 때문에 true인 것을 확인 할 수 있음.
'IaC👩💻 > Ansible' 카테고리의 다른 글
| [Ansible] Galaxy (0) | 2024.08.23 |
|---|---|
| [Ansible] Playbook (0) | 2024.08.23 |
| [Ansible] 개요 및 설치 (0) | 2024.08.23 |
