- hosts: localhost
gather_facts: true
tasks:
- debug:
msg: Disk nvme0n1 exists.
when: "'nvme0n1' in ansible_devices.keys()|list"
- debug:
msg: Disk sdb does not exist.
when: "'sdb' not in ansible_devices.keys()|list"
https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html
```bash
root@DESKTOP-F4T7TCG:/home/ansible# more disk.yml
---
- name: test disk information check
hosts: vm
tasks:
- name: disk check
debug:
msg: "{{ ansible_facts['devices'] }}"
- name: check True or not
debug:
msg: Disk sdb doest not exist
when: "'sdb' not in ansible_devices.keys()|list"
- name: check disk not
copy:
content: "{{ ansible_facts['devices']['sdb']['size'] }}"
dest: "/home/{{ansible_fqdn}}-diskinfo.txt"
delegate_to: localhost
when: "'sdb' in ansible_devices.keys()| list"
```
============
- name: chel
shell: |
echo "
node_kernel_size(name='{{ ansible_hostname }}') '{{ ansible_kernel }}'
node_disk_size(name='{{ ansible_hostname }}') '{{ ansible_facts.devices.sdb.size }}'
" >> /home/ansible/info.txt
# dest: "/home/ansible/{{ansible_fqdn}}-info.txt"
# delegate_to: localhost
when: "'sdb' in ansible_devices.keys()| list"
=========== prom으로 사용할려면 ========= \"를 앞뒤 추가해줘야한다
systemctl restart node_exporter
journalctl -eu node_exporter
workshop_student_is_happy{campus="campusX"} 1
curl localhost:9100/metrics
curl -s localhost:9100/metrics | grep workshop
- name: chel
shell: |
echo "
node_kernel_size{name=\""{{ ansible_hostname }}"\",output=\""{{ ansible_kernel }}"\"} 0
node_disk_size{name=\""{{ ansible_hostname }}"\",size=\""{{ ansible_facts.devices.sdb.size }}"\"} 0
" >> /home/ansible/info.txt
# dest: "/home/ansible/{{ansible_fqdn}}-info.txt"
# delegate_to: localhost
when: "'sdb' in ansible_devices.keys()| list"
==============================================================
----
- name: test disk information check
hosts: vm
tasks:
- name: disk check if yes
shell: |
echo "
node_kernel_size{name=\""{{ ansible_hostname }}"\",output=\""{{ ansible_kernel }}"\",disk=\""{{ ansible_facts.devices.sdb.size}} "\"} 0
" > /home/ansible/info.txt
# dest: "/home/ansible/{{ansible_fqdn}}-info.txt"
# delegate_to: localhost
when: "'sdb' in ansible_devices.keys()| list"
- name: disk check if no
shell: |
echo "
node_kernel_size{name=\""{{ ansible_hostname }}"\",output=\""{{ ansible_kernel }}"\",disk=\""0"\"} 0
" > /home/ansible/info.txt
# dest: "/home/ansible/{{ansible_fqdn}}-info.txt"
# delegate_to: localhost
when: "'sdcxb' not in ansible_devices.keys()| list"
'나는 노동자 > LINUX' 카테고리의 다른 글
ansible extra vars (0) | 2023.02.13 |
---|---|
ansible 물리서버, 가성서버 확인 (0) | 2023.02.07 |
리눅스 임시 포트 오픈 (0) | 2023.01.12 |
xfs volume extend (0) | 2020.07.10 |
Log Rate Limitimg in Linux (0) | 2018.09.17 |