본문 바로가기

Project

Ansible 설치 및 구성

Ansible 설치 및 구성

제어 노드(control)에서 Ansible을 다음과 같이 구성하였습니다.

 

프로그램 구성

HOSNNAME NODE IP ADDRESS DESCRIPTION
control.lab.example.com control 172.25.250.254 ansible control node
classroom.lab.example.com classroom 172.25.250.254 materials
content.lab.example.com content 172.25.250.254 YUM repo
node1.lab.example.com node1 172.25.250.9 ansible managed node
node2.lab.example.com node2 172.25.250.10 ansible managed node
node3.lab.example.com node3 172.25.250.11 ansible managed node
node4.lab.example.com node4 172.25.250.12 ansible managed node
node5.lab.example.com node5 172.25.250.13 ansible managed node
utility.lab.example.com utilit 172.25.250.220 utility

 


1. 필요한 패키지 설치

먼저, 제어 노드에 접속한 후 필요한 패키지를 설치합니다.

# control 노드 접속
ssh greg@control

# Ansible 및 관련 패키지 설치
sudo dnf -y install ansible-automation-platform-common.noarch ansible-navigator

2. 디렉토리 구조 생성

Ansible 작업을 위한 디렉토리 구조를 생성합니다.

# 디렉토리 생성
mkdir -p /home/greg/ansible/roles
mkdir /home/greg/ansible/mycollection
cd /home/greg/ansible

3. Ansible 구성 파일 생성

Ansible 구성 파일(ansible.cfg)을 생성하고 필요한 설정을 추가합니다.

# 기본 구성 파일 생성
ansible-config init --disabled > /home/greg/ansible/ansible.cfg

# 구성 파일 편집
vim /home/greg/ansible/ansible.cfg

 

다음과 같이 구성 파일을 설정합니다.

[defaults]
inventory = /home/greg/ansible/inventory
remote_user = greg
host_key_checking = False
roles_path = /home/greg/ansible/roles:/usr/share/ansible/roles
collections_path = ./mycollection/:.ansible/collections:/usr/share/ansible/collections

[privilege_escalation]
become=True

4. 구성 파일 확인

구성 파일이 정상적으로 적용되었는지 확인합니다.

# Ansible 버전 및 설정 확인
ansible --version

# Ansible Galaxy 컬렉션 목록 확인
ansible-galaxy list

5. 정적 인벤토리 파일 생성

호스트 그룹을 정의하는 정적 인벤토리 파일(inventory)을 생성합니다.

# 인벤토리 파일 생성
vim /home/greg/ansible/inventory

 

다음과 같이 호스트 그룹을 구성합니다.

[dev]
node1

[test]
node2

[prod]
node3
node4

[balancers]
node5

[webservers:children]
prod

6. 인벤토리 확인 및 테스트

인벤토리 파일이 정상적으로 구성되었는지 확인하고, 모든 호스트에 대해 Ping 테스트를 수행합니다.

# 인벤토리 구조 확인
ansible-inventory --graph

# 모든 호스트에 Ping 테스트
ansible all -m ping

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

'Project' 카테고리의 다른 글

Ansible 하드웨어 보고서 생성하기  (0) 2025.02.25
Ansible 파티션 설정  (0) 2025.02.25
Ansible 웹서버 구축  (0) 2025.02.25
Ansible 사용자 계정 생성하기  (0) 2025.02.25