Server H/W Specfication
NO | Model | IOS | Role | 현황 | 비고 |
---|---|---|---|---|---|
1 | Cisco WS-C3560G-48TS | 12.2(58)SE2 (C3560-IPSERVICESK9-M) | 유저서비스용 1Gbps | GO | Layer 3 |
2 | Cisco WS-C3560G-24TS | 12.2(58)SE2 (C3560-IPSERVICESK9-M) | 관리자용 1Gbps | GO | Layer 3 |
3 | Cisco WS-C3750G-48TS | 12.2(35)SE5 (C3750-IPSERVICES-M) | 개발용 1Gbps | GO | Layer 3 |
4 | Cisco WS-C3750-48TS | 12.2(44)SE3 (C3750-IPSERVICESK9-M) | Swtich Exchange | GO | Layer 3 |
5 | Cisco WS-C3750-48TS | 12.2(50)SE3 (C3750-IPSERVICESK9-M) | DBMS Routing (100Mbps) | GO | Layer 3 |
6 | Cisco WS-C2960G-24TC-L | 12.2(53)SE1 (C2960-LANBASEK9-M) | DBMS 1Gbps | GO | Layer 2 |
Ansible을 통한 정보수집 준비
- inventory 작성
- host variables 파일 작성
- ansible.cfg 파일 작성 (Optional)
# cat inventory
[hongsnet]
10.10.10.1 managed_ip=10.10.10.1 des=IX_SWITCH
10.10.10.2 managed_ip=10.10.10.2 des=HONGS_SWITCH
20.20.20.2 managed_ip=20.20.20.2 des=TB2_SWITCH
30.30.30.2 managed_ip=30.30.30.2 des=TB3_SWITCH
40.40.40.2 managed_ip=40.40.40.2 des=DB_L3_SWITCH
180.180.180.254 managed_ip=180.180.180.254 des=DB_L2_SWITCH
inventory 파일에는 대상이 되는 호스트를 기록하는데, hongsnet
이라는 호스트그룹에 접속할 IP 주소와 내부에서 사용할 기준정보인 IP 주소를 사용하기 위해 managed_ip
라는 변수를 설정한다.
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을 이용한 시스템정보 수집
---
- hosts: hongsnet
gather_facts: no
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: Switch Commands
telnet:
user: 유저_아이디
password: 유저_패스워드입력
login_prompt: "Username: "
prompts:
- "[>|#]|Password: "
command:
- terminal length 0
- enable
- enable_패스워드입력
- show version
- show run
- show vlan
- show ip route
register: output
- debug: var=output
- name: Local TXT File Output Version
local_action: copy content={{ output.output[3] }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/version.txt
- name: Local TXT File Output Running Config
local_action: copy content={{ output.output[4] }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/running_config.txt
- name: Local TXT File Output Vlan
local_action: copy content={{ output.output[5] }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/vlan.txt
- name: Local TXT File Output Routing Table
local_action: copy content={{ output.output[6] }} dest=./RESULT/{{ managed_ip }}/{{ year }}/{{ month }}/{{ day }}/routing_table.txt
- telnet으로 Switch에 접속하여 정보를 취합하기 때문에 host 변수파일은 별도로 구성하지않고, 파일에 사용자/패스워드를 기입한다.
Playbook 수집내역 설명
- Switch Version, IOS 버전을 수집한다.
- Running Config를 수집한다.
- vlan 및 라우팅테이블 내역을 수집한다.
구성내역
# ls
RESULT ansible.cfg inventory switch_info.yml
파일 및 디렉토리의 구성은 다음과 같다.
# tree -L 4
.
├── RESULT
│ ├── 10.10.10.1
│ │ └── 2021
│ │ └── 03
│ ├── 10.10.10.2
│ │ └── 2021
│ │ └── 03
│ ├── 180.180.180.254
│ │ └── 2021
│ │ └── 03
│ ├── 20.20.20.2
│ │ └── 2021
│ │ └── 03
│ ├── 30.30.30.2
│ │ └── 2021
│ │ └── 03
│ └── 40.40.40.2
│ └── 2021
│ └── 03
├── ansible.cfg
├── inventory
└── switch_info.yml
19 directories, 3 files
ansible Playbook 수행
# ansible-playbook switch_info.yml