Server H/W Specfication
NO | CPU | MEM | DISK | Role | 현황 | 비고 |
---|---|---|---|---|---|---|
1 | Intel(R) Xeon(R) E5620 @ 2.40GHz (Quad) * 2 | 64 GB (DDR3) | SATA 2 TB * 4 (RAID 10) | 개발용 + Front-End | GO | DELL R410 |
2 | Intel(R) Xeon(R) E31220 @ 3.10GHz (Quad) * 1 | 32 GB (DDR3) | SATA 2 TB * 2 (Software RAID, Level 1) | STAG + Front-End | GO | HP DL120 G9 |
3 | Intel(R) Xeon(R) E5645 @ 2.40GHz (Hexa) * 2 | 148 GB (DDR3) | SATA 1TB * 6 (RAID 10) | Admin 용도 + WORKER | GO | DELL R710 |
4 | Intel(R) Xeon(R) X5650 @ 2.67GHz (Hexa) * 2 | 256 GB (DDR3) | SATA 2TB * 6 (RAID 10) | Virtualization + WORKER | GO | DELL R710 |
5 | Intel(R) Xeon(R) E5645 @ 2.40GHz (Hexa) * 2 | 128 GB (DDR3) | SATA 2TB * 4 (RAID 10) | STORAGE + MANAGER | GO | DELL R710 |
6 | Intel(R) Xeon(R) X5650 @ 2.67GHz (Hexa) * 2 | 64 GB (DDR3) | SATA 2TB * 4 (RAID 10) | DBMS + Virtualization | GO | DELL R410 |
7 | Intel(R) Xeon(R) E5620 @ 2.40GHz (Quad) * 2 | 64 GB (DDR3) | SAS 600GB * 2 (Software RAID, Level 1) | WORKER | GO | IBM X3550 M2 |
Ansible을 통한 정보수집 준비
- inventory 작성
- host variables 파일 작성
- ansible.cfg 파일 작성 (Optional)
inventory 작성
# cat inventory
[hongsnet]
192.168.200.62 managed_ip=192.168.200.62
192.168.200.217 managed_ip=192.168.200.217
172.24.0.151 managed_ip=172.24.0.151
172.16.0.158 managed_ip=172.16.0.158
172.24.0.245 managed_ip=172.24.0.245
180.180.180.250 managed_ip=180.180.180.250
172.16.0.251 managed_ip=172.16.0.251
inventory 파일에는 대상이 되는 호스트를 기록하는데, hongsnet
이라는 호스트그룹에 접속할 IP 주소와 내부에서 사용할 기준정보인 IP 주소를 사용하기 위해 managed_ip
라는 변수를 설정한다.
host variables 파일 작성
호스트 변수의 경우 host_var 디렉토리 아래에 위치하면, 호스트 IP별로 설정한다. 또한 su
method를 사용하여 일반 -> root 유저로의 switching을 진행한다.
# cat host_vars/172.16.0.158
ansible_ssh_host: 172.16.0.158
ansible_ssh_port: ssh 포트번호
ansible_ssh_user: joohanhong
ansible_ssh_pass: "유저 패스워드"
ansible_become: yes
ansible_become_method: su
ansible_become_user: root
ansible_become_pass: "root 패스워드"
ansible_python_interpreter: python2.7
ansible.cfg 파일 작성 (Optional)
ansible.cfg 파일은 환경설정이 파일이며, Global 경로는 /etc/ansible/ansible.cfg
이며, 아래와 같이 특정 디렉토리안에 위치하면, 먼저 읽어들이게 된다.
cat ansible.cfg
[defaults] inventory = ./inventory host_key_checking = False timeout= 10
참고적으로 inventory 파일로는 현재 경로의 inventory 파일을 사용하는데, ansible-playbook 명령 실행 시 -i 옵션으로 지정할 수도 있다.
Ansible Playbook을 이용한 시스템정보 수집
# cat system_info.yml
---
- hosts: hongsnet
vars:
#time: "{{lookup('pipe','date \"+%Y-%m-%d %H:%M:%S\"')}}"
year: "{{lookup('pipe','date \"+%Y\"')}}"
month: "{{lookup('pipe','date \"+%m\"')}}"
day: "{{lookup('pipe','date \"+%d\"')}}"
tasks:
- name: Local Date Directory Create
local_action: command mkdir -p ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}
- name: Local TXT File H/W init
shell: echo "" > ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/hw_info
delegate_to: localhost
- name: Local TXT File H/W Result
lineinfile:
line: "{{ item }}"
create: yes
insertafter: EOF
dest: ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/hw_info
state: present
with_items:
- "Vendor: {{ ansible_system_vendor }}"
- "\nModel: {{ ansible_product_name }}"
- "\nBIOS Date: {{ ansible_bios_date }}"
- "\nBIOS Version: {{ ansible_bios_version }}"
delegate_to: localhost
- name: Local TXT File hostname Result
local_action: copy content={{ ansible_hostname }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/hostname
- name: Local TXT File Date init
shell: echo "" > ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/date_timezone
delegate_to: localhost
- name: Local TXT File Date Result
lineinfile:
line: "{{ item }}"
create: yes
insertafter: EOF
dest: ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/date_timezone
state: present
with_items:
- "\nDATE: {{ ansible_date_time.date }}"
- "\nTimeZone: {{ ansible_date_time.tz }}"
delegate_to: localhost
- name: Local TXT File OS and Kernel Version init
shell: echo "" > ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/os_versions
delegate_to: localhost
- name: Local TXT File OS and Kernel Version Result
lineinfile:
line: "{{ item }}"
create: yes
insertafter: EOF
dest: ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/os_versions
state: present
with_items:
- "Distribution: {{ ansible_distribution }}"
- "\nRelease: {{ ansible_distribution_release }}"
- "\nDistribution Version: {{ ansible_distribution_version }}"
- "\nKernel: {{ ansible_kernel }}"
- "\nArchitecture: {{ ansible_architecture }}"
delegate_to: localhost
- name: CPU Info File Result
shell: cat /proc/cpuinfo
register: cpuinfo
- name: CPU Model Info Result
shell: cat /proc/cpuinfo | grep "model name" | cut -d':' -f2 | uniq
register: cpu_model
- name: CPU Info Detail Result
shell: /usr/sbin/dmidecode | grep -A 8 "Processor Information"
register: cpu_detail
- name: CPU Hyperthreading Check Result
shell: /usr/sbin/dmidecode -t processor | grep HTT | head -1
register: cpu_hyper
- name: CPU Cores Count Result
shell: cat /proc/cpuinfo |grep processor |wc -l
register: cpu_cores
- name: CPU Physical Core Count Result
shell: cat /proc/cpuinfo |grep 'cpu cores' |tail -1
register: cpu_phisical
- name: CPU Thread/Core Check Result
shell: /usr/sbin/dmidecode -t processor | egrep 'Core Count|Thread Count' | head -2
register: cpu_thread
- name: CPU Socket Check Result
shell: /usr/sbin/dmidecode -t processor |grep 'Socket Designation'
register: cpu_socket
- name: CPU Result File init
shell: echo "" > ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/cpu_information
delegate_to: localhost
- name: CPU Information Result
lineinfile:
line: "{{ item }}"
create: yes
insertafter: EOF
dest: ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/cpu_information
with_items:
- "Model: {{ cpu_model.stdout }}"
- "\nDetail INFO: {{ cpu_detail.stdout }}"
- "\nHyperthreading Check: {{ cpu_hyper.stdout }}"
- "\nCores Count: {{ cpu_cores.stdout }}"
- "\nThread/Core: {{ cpu_thread.stdout }}"
- "\nSocket: {{ cpu_socket.stdout }}"
delegate_to: localhost
- name: Memory Size Result
shell: cat /proc/meminfo |grep MemTotal; free -g
register: memory_size
- name: Memory Total Bank Result
shell: /usr/sbin/dmidecode -t 17 |egrep 'Memory|Device' |wc -l
register: memory_bank
- name: Memory Per Bank Size Result
shell: /usr/sbin/dmidecode -t 17 |egrep 'Memory|Size' |egrep -v 'No|Device'
register: memory_bank_size
- name: Memory Result File init
shell: echo "" > ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/mem_information
delegate_to: localhost
- name: Memory Information Result
lineinfile:
line: "{{ item }}"
create: yes
insertafter: EOF
dest: ./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/mem_information
with_items:
- "Total Size: {{ memory_size.stdout }}"
- "\nMemory Bank: {{ memory_bank.stdout }}"
- "\nMemory Bank PerSize: {{ memory_bank_size.stdout }}"
delegate_to: localhost
- name: fdisk Command Result
shell: /usr/sbin/fdisk -l
register: fdisk_l
- name: Local TXT File fdisk -l Result
local_action: copy content={{ fdisk_l.stdout }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/fdisk
- name: smartctl Command Result
shell: /usr/sbin/smartctl -a /dev/sda -d megaraid,0 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,1 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,2 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,3 | head -n 25
register: smartctl_result_group1
when: managed_ip == '192.168.200.62' or managed_ip == '180.180.180.250'
- name: Local TXT File smartctl Group1 Result
local_action: copy content={{ smartctl_result_group1.stdout }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/disk_information
when: managed_ip == '192.168.200.62' or managed_ip == '180.180.180.250'
- name: smartctl Command Result
shell: /usr/sbin/smartctl -a /dev/sda -d megaraid,0 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,1 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,2 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,3 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,4 | head -n 25; /usr/sbin/smartctl -a /dev/sda -d megaraid,5 | head -n 25
register: smartctl_result_group2
when: managed_ip == '172.16.0.158' or managed_ip == '172.24.0.151' or managed_ip == '172.24.0.245'
- name: Local TXT File smartctl Group2 Result
local_action: copy content={{ smartctl_result_group2.stdout }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/disk_information
when: managed_ip == '172.16.0.158' or managed_ip == '172.24.0.151' or managed_ip == '172.24.0.245'
- name: smartctl Command Result
shell: /usr/sbin/smartctl -a /dev/sda | head -n 25; /usr/sbin/smartctl -a /dev/sdb | head -n 25; /usr/sbin/smartctl -a /dev/sdc | head -n 25; /usr/sbin/smartctl -a /dev/sdd | head -n 25
register: smartctl_result_group3
when: managed_ip == '192.168.200.217'
- name: Local TXT File smartctl Group3 Result
local_action: copy content={{ smartctl_result_group3.stdout }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/disk_information
when: managed_ip == '192.168.200.217'
- name: smartctl Command Result
shell: /usr/sbin/smartctl -a /dev/sdc | head -n 25; /usr/sbin/smartctl -a /dev/sdd | head -n 25; /usr/sbin/smartctl -a /dev/sde | head -n 25; /usr/sbin/smartctl -a /dev/sdf | head -n 25
register: smartctl_result_group4
when: managed_ip == '172.16.0.251'
- name: Local TXT File smartctl Group4 Result
local_action: copy content={{ smartctl_result_group4.stdout }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/disk_information
when: managed_ip == '172.16.0.251'
Playbook 수집내역 설명
- System Board, CPU, Memory, Disk에 대한 정보를 수집한다.
- ansible의 Facts와 linux command를 이용하여 정보를 수집한다.
- 수집되는 결과는 현재 경로의 ./RESULT/IP주소/년도/월/일/항목 으로 기록된다.
- DISK 정보의 경우 서버마다 RAID 및 디스크구성이 다르므로, Group으로 구분한다.
구성내역
# ls
RESULT ansible.cfg host_vars inventory system_info.retry system_info.yml
파일 및 디렉토리의 구성은 다음과 같다.
# tree -L 4
.
├── RESULT
│ ├── 172.16.0.158
│ │ └── 2021
│ │ ├── 02
│ │ └── 03
│ ├── 172.16.0.251
│ │ └── 2021
│ │ ├── 02
│ │ └── 03
│ ├── 172.24.0.151
│ │ └── 2021
│ │ ├── 02
│ │ └── 03
│ ├── 172.24.0.245
│ │ └── 2021
│ │ ├── 02
│ │ └── 03
│ ├── 180.180.180.250
│ │ └── 2021
│ │ ├── 02
│ │ └── 03
│ ├── 192.168.200.217
│ │ └── 2021
│ │ ├── 02
│ │ └── 03
│ └── 192.168.200.62
│ └── 2021
│ ├── 02
│ └── 03
├── ansible.cfg
├── host_vars
│ ├── 172.16.0.158
│ ├── 172.16.0.245
│ ├── 172.16.0.251
│ ├── 172.24.0.151
│ ├── 172.24.0.245
│ ├── 180.180.180.250
│ ├── 192.168.200.217
│ └── 192.168.200.62
├── inventory
├── system_info.retry
└── system_info.yml
30 directories, 12 files
ansible Playbook 수행
# ansible-playbook system_info.yml