[Ansible] 01. Ansible 설치
카테고리: ANSIBLE
태그: ansible
[Ansible] 01. Ansible 설치
🔔 시작하기 전 …
[IaC] 04. Configuration 도구 (2) - Ansible : https://revenge1005.github.io/iac/4/
[IaC] 02. Configuration 도구의 주요 특징 : https://revenge1005.github.io/iac/2/
예제 Github : https://github.com/revenge1005/Ansible_study
🔔 Ansible 설치
(a) Install Ansible
# Ubuntu 또는 Debian의 경우
sudo apt update; sudo apt install software-properties-common -y
sudo add-apt-repository --yes --update ppa:ansible/ansible -y
sudo apt install ansible -y
# RHEL 또는 CentOS의 경우
dnf update -y; dnf install epel-release -y; dnf install ansible -y
ansible --version
(b) Managed 노드 - 대상 서버 구성
# Ubuntu 또는 Debian의 경우
apt install openssh-server -y
systemctl restart ssh; systemctl enable ssh
ufw allow 22
# RHEL 또는 CentOS의 경우
dnf install openssh-server -y
systemctl restart sshd; systemctl enable sshd
firewall-cmd --zone=public --permanent --add-port=22/tcp
(c) Control 노드 - SSH 키 생성
cat <<EOF >>/etc/hosts
# Control Node.
192.168.219.100 control control.test.com
# Ansible Managed Nodes.
192.168.219.201 node01 node01.test.com
192.168.219.202 node02 node02.test.com
EOF
ssh-keygen -t ed25519 -C "Ansible Test"
ll .ssh/
합계 12
-rw------- 1 root root 399 5월 4 16:41 id_ed25519
-rw-r--r-- 1 root root 94 5월 4 16:41 id_ed25519.pub
-rw-r--r-- 1 root root 354 4월 27 23:42 known_hosts
for i in node01 node02;
do
ssh-copy-id -i ~/.ssh/id_ed25519.pub $i
done
(d) Control 노드 - 인벤토리 작성
mkdir ansible_test
cd ansible_test
cat <<EOF > inventory
node01
node02
EOF
cat <<EOF > ansible.cfg
[defaults]
inventory = inventory
private_key_file = ~/.ssh/id_ed25519
EOF
(e) Control 노드 - 모든 managed 노드 ping 테스트
# ansible -m ping all
node02 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
node01 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
}
(f) Control 노드 - Managed Node 상세 정보 확인
## 모든 노드에 대한 상세 정보
ansible all -m gather_facts
## 특정 노드 지정
ansible node01 -m gather_facts
ansible all -m gather_facts --limit node01
댓글 남기기