Ansible(앤서블) 설치 및 기본 설정
[ 구성 ]
OS - CentOs 7
Master 서버 1대 ( 제어서버 )
Client 서버 3대 ( 관리대상서버 )
1. 설치
-Master서버만 설치 필요 , Client서버는 별도의 프로그램 설치 필요없음
[root@MANAGER ~]# yum -y install ansible
2. 관리대상 서버 등록
- /etc/ansible/hosts(관리대상서버 리스트 설정 파일) 파일에 관리하고자 하는 대상 서버 목록 입력
(예시)
-------------------------------------------
[MOGI] #관리 대상 그룹명
10.0.2.5 #관리대상 서버 IP
10.0.2.6 #관리대상 서버 IP
10.0.2.7 #관리대상 서버 IP
-------------------------------------------
vi /etc/ansible/hosts
4 #
5 # - Comments begin with the '#' character
6 # - Blank lines are ignored
7 # - Groups of hosts are delimited by [header] elements
8 # - You can enter hostnames or ip addresses
9 # - A hostname/ip can be a member of multiple groups
10
11 # Ex 1: Ungrouped hosts, specify before any group headers.
12
13 ## green.example.com
14 ## blue.example.com
15 ## 192.168.100.1
16 ## 192.168.100.10
17
18 # Ex 2: A collection of hosts belonging to the 'webservers' group
19
20 ## [webservers]
21 ## alpha.example.org
22 ## beta.example.org
23 ## 192.168.1.100
24 ## 192.168.1.110
25
26 # If you have multiple hosts following a pattern you can specify
27 # them like this:
28
29 ## www[001:006].example.com
30
31 # Ex 3: A collection of database servers in the 'dbservers' group
32
33 ## [dbservers]
34 ##
35 ## db01.intranet.mydomain.net
36 ## db02.intranet.mydomain.net
37 ## 10.25.1.56
38 ## 10.25.1.57
39
40 # Here's another example of host ranges, this time there are no
41 # leading 0s:
42
43 ## db-[99:101]-node.example.com
44
45 [MOGI]
46 10.0.2.5
47 10.0.2.6
48 10.0.2.7
3. 관리 대상 서버 known_hosts_key 값 입력
- 관리 대상 서버들의 known_hosts_key 값 입력받기 위하여 아래와 같이 명령어 입력후
노드 수 만큼 'yes' 입력 , 3개의 클라이언트 서버니 총 세번 입력 필요
[root@MANAGER ~]# ansible MOGI -m ping
4. 관리 대상 서버 통신 확인
- 이제 위에서 사용한 명령어에서 -k옵션을 추가하여 통신 확인 '-k'는 패스워드를 입력하는 옵션으로 세 서버가 동일한 패스워드를 사용하고 있어야함
[root@MANAGER ~]# ansible MOGI -m ping -k
SSH password:
10.0.2.6 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.0.2.7 | SUCCESS => {
"changed": false,
"ping": "pong"
}
10.0.2.5 | SUCCESS => {
"changed": false,
"ping": "pong"
}