ansible 설치(Ubuntu)
작업 순서
- 설치 준비
- Ansible 설치
- ssh 키 생성
- inventory / 관리 서버 - host/group 설정
설치 준비
- python과 pip가 필요
- ansible 문서를 참고하여 각 버전별 python을 확인 및 설치 한다.
- https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html#control-node-requirements
1. python3 / pip 버전 확인
# 버전 확인
python3 -m pip -V
# pip 설치 - 찾을 수 없는 경우
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --user
2. python3 버전 업그레이드(ubuntu)
https://www.debugpoint.com/install-python-3-11-ubuntu/
// 설치
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt install software-properties-common -y
sudo apt install python3.11
# 버전 선택
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 2
sudo update-alternatives --config python3
# 버전 확인
python3 -m pip -V
Ansible 설치
# 설치
python3 -m pip install --user ansible
# 설치 버전 확인
ansible --version
python3 -m pip show ansible
설치 중 아래와 같은 메세지가 출력이되면 .bashrc 파일에 ansible 경로를 추가한다.
WARNING: The script ansible-community is installed in '/home/jj/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
.bashrc 편집
vi .bashrc
# path에 경로 추가
LOCAL_BIN=/home/jj/.local/bin
export PATH=$JAVA_HOME/bin:$LOCAL_BIN:$PATH
# 적용 또는 재 로그인
source .bashrc
ssh 키 생성
- 관리 대상 서버와 ssh 통신에서 사용할 private/public 키 생성
# 키 생성
ssh-keygen -t rsa -b 4096 -f ~/.ssh/server_rsa
# public 키 복사
ssh-copy-id vagrant@192.168.0.20
inventory - host/group 설정
- 서버 정보 등록
- https://docs.ansible.com/ansible/latest/inventory_guide/intro_inventory.html
- 기본 설정파일 : /etc/ansible/hosts
- 없는 경우 만들어야함
- 경로 옵션 -i
- ansible server -i test-server-hosts -m ping
- 대상 그룹이 여러개 일때 개별 파일로 만들어서 하는게 편할 듯하다.
[all:vars]
ansible_connection=ssh
ansible_user=vagrant
[server]
192.168.0.20
192.168.0.21
또는
[server]
192.168.0.20 ansible_connection=ssh ansible_user=vagrant
확인
// ping 테스트
ansible server -m ping
// 경로 지정
ansible server -i test-server-hosts -m ping
// 개별 테스트
ansible 192.168.0.20 -m ping
'서버' 카테고리의 다른 글
[nginx] nginx + https + vue3 + Docker (0) | 2023.10.27 |
---|---|
[Jenkins] ssh - db import 한글깨짐 / manpath: can't set the locale; make sure $LC_* and $LANG are correct (0) | 2023.03.07 |
[Vagrant] - 테스트 서버 생성 (0) | 2022.04.27 |
[Docker] 컨테이너간 통신 (0) | 2021.09.07 |
[Docker] volume 백업/복원 (0) | 2021.09.03 |