2022이전/Centos7

docker contianer에 ansible 세팅하기

바로퇴장 2021. 6. 11. 17:08

서버 환경 :
docker Version: 18.09.2

컨테이너 :
IMAGE => centos:7
3EA => 1EA : ansible controller(172.17.0.4) / 2EA : Client(172.17.0.2/172.17.0.3)

초기 세팅

#create container
docker run --privileged -d --name ansible_controller centos:7 init
docker run --privileged -d --name ansible_client1 centos:7 init
docker run --privileged -d --name ansible_client2 centos:7 init

#excute container
docker exec -it ansible_controller /bin/bash
docker exec -it ansible_client1 /bin/bash
docker exec -it ansible_client2 /bin/bash

ansible_controll 설치 및 세팅

docker 
#controller 
#도커 이미지는 아주 기본적인것만 설치되어 있기 때문에 ansible에 필요한 요소들을 설치해준다.
#ssh 접속에 필요한 패키지
yum install sudo net-tools openssh-server openssh-client -y
systemctl start sshd
netstat -lntp 
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      509/sshd
tcp6       0      0 :::22                   :::*                    LISTEN      509/sshd

#install ansible
yum install ansible -y

ansibe_client 설치 및 세팅

#client
yum install net-tools openssh-server openssh-client -y
systemctl start sshd
netstat -lntp

ansible controller to client

#client
adduser ansibleClient 
vi /etc/sudoers
~~~
## Allow root to run any commands anywhere
root    ALL=(ALL)       ALL
ansibleClient ALL=(ALL)         ALL
~~~

#controller
ssh-keygen
ssh-copy-id ansibleClient@172.17.0.2
ssh-copy-id ansibleClient@172.17.0.3

TEST

ansible -u ansibleClinet 

 

 

작성중