1. SSH 키 배포 (초기 설정)
SSH 키 생성 (제어 노드에서)
ssh-keygen
# → 엔터 3번 (기본 경로 및 패스프레이즈 없이 생성)
대상 노드에 공개 키 배포
for i in {1..5}; do
ssh-copy-id -i ~/.ssh/id_rsa.pub root@ygbaek0${i}.gitcluster.com
done
비밀번호 없이 SSH 접속 가능
2. 설정 파일
/etc/ansible/ansible.cfg
[defaults]
inventory=/etc/ansible/hosts
# SSH 최초 접속 시 host key 확인 절차 생략
host_key_checking = False
3. 인벤토리 파일
/etc/ansible/hosts
[cluster]
ygbaek01.cluster.com
ygbaek02.cluster.com
ygbaek03.cluster.com
ygbaek04.cluster.com
ygbaek05.cluster.com
[all:vars]
# ansible_python_interpreter=/usr/bin/python3
# required
# ssh 접속 포트 및 계정 정보
ansible_port=22
ansible_user=root
ansible_ssh_pass=root # SSH 키 배포 후에는 생략 가능
4. Ad-Hoc 명령어 예시
# yum repository 파일 복사
ansible cluster -m copy --args "src=/etc/yum.repos.d/rhel8.repo dest=/etc/yum.repos.d/rhel8.repo"
# hosts 파일 복사
ansible cluster -m copy --args "src=/etc/hosts dest=/etc/hosts"
# yum 캐시 삭제
ansible cluster -m shell -a 'yum clean all'
# yum 저장소 목록 확인
ansible cluster -m shell -a 'yum repolist'
# python2 설치
ansible cluster -m yum -a "name=python2 state=present"
# firewalld 중지 및 비활성화 (sudo 권한 필요)
ansible cluster -m shell -a "systemctl stop firewalld && systemctl disable firewalld" -b'Linux > Ansible' 카테고리의 다른 글
| Ansible 구성 요소를 활용한 배포 자동화 (0) | 2025.08.27 |
|---|