728x90
반응형
엔서블 서버에서 각 노드에 대한 시스템 정보를 추출하면 화면
--> 자원정보 결과를 각 노드 /var/log/daily_check 파일에 저장함
서버 해당 정보
서버IP | 호스트명 | Node 명 |
192.168.56.50 | Ansible-Server | |
192.168.56.51 | Ansible-Node01 | tnode1-cetnos.exp.com |
192.168.56.54 | Ansible-Node04 | tnode2-ubuntu.exp.com |
192.168.56.57 | Ansible-Node07 | tnode3-rhel.exp.com |
/etc/hosts 파일 및 ANSIBLE 인벤토리 파일 inventoy or hosts 파일 /etc/ansible/
# 자원정보 추출 yml 파일 * (실행) # ansible-playbook monitoring_facts.yml
---
- hosts: tnode
vars:
log_directory: /var/log/daily_check
tasks:
- name: Print system info
ansible.builtin.debug:
msg:
- "################ Start #####################"
- "Date: {{ ansible_facts.date_time.date }} {{ ansible_facts.date_time.time }}"
- "HostName: {{ ansible_facts.hostname }}"
- "OS: {{ ansible_facts.distribution }}"
- "OS Version: {{ ansible_facts.distribution_version }}"
- "OS Kernel: {{ ansible_facts.kernel }}"
- "CPU Cores: {{ ansible_facts.processor_vcpus }}"
- "Memory: {{ ansible_facts.memory_mb.real }}"
- "Interfaces: {{ ansible_facts.interfaces }}"
- "IPv4: {{ ansible_facts.all_ipv4_addresses }}"
- "Devices: {{ ansible_facts.mounts }}"
- "################# End #######################"
register: result
- name: Create log directory
ansible.builtin.file:
path: "{{ log_directory }}"
state: directory
- name: Print logs to log file
ansible.builtin.shell: |
echo "{{ item }}" >> "{{ log_directory }}"/system_info.logs
loop: "{{ result.msg }}"
# 추출결과 각 노드 파일의 /var/log/daily_check/system_info.logs 로그로 저장됨
################ Start #####################
Date: 2023-12-23 15:25:20
HostName: ansible-node04
OS: Ubuntu
OS Version: 18.04
OS Kernel: 4.15.0-213-generic
CPU Cores: 1
Memory: {u'total': 481, u'used': 446, u'free': 35}
Interfaces: [u'lo', u'eth1', u'eth0']
IPv4: [u'192.168.56.54', u'10.0.2.15']
Devices: [{u'block_used': 1280265, u'uuid': u'29b74d93-f08b-42be-ae5c-a61723438b4e', u'size_total': 42235019264, u'block_total': 10311284, u'mount': u'/', u'block_available': 9031019, u'size_available': 36991053824, u'fstype': u'ext4', u'inode_total': 2621440, u'options': u'rw,relatime,data=ordered', u'device': u'/dev/sda1', u'inode_used': 145297, u'block_size': 4096, u'inode_available': 2476143}]
################# End #######################
728x90
반응형
LIST
'Ansible' 카테고리의 다른 글
Ansible - 08 (rols 설치) (1) | 2023.12.23 |
---|---|
Ansible - 07 (실습하기 좋은 Vagrant 파일) (2) | 2023.12.23 |
Ansible - 05 (python3 설정) (1) | 2023.12.17 |
Ansible - 04 (Ansible_galaxy) (0) | 2023.12.17 |
Ansible - 03 (Ansible_playbook) (0) | 2023.12.17 |