104 lines
2.8 KiB
YAML
104 lines
2.8 KiB
YAML
---
|
|
- hosts: all
|
|
gather_facts: yes
|
|
become: true
|
|
become_user: root
|
|
become_method: sudo
|
|
vars:
|
|
remote_dir: /opt/sensusagent
|
|
local_bin_dir: "{{ LOCAL_BIN_DIR | default('./bin/agent') }}"
|
|
tasks:
|
|
- name: Detect package manager (Debian/Ubuntu)
|
|
ansible.builtin.stat:
|
|
path: /etc/debian_version
|
|
register: debian_like
|
|
|
|
- name: Detect package manager (RHEL/CentOS)
|
|
ansible.builtin.stat:
|
|
path: /etc/redhat-release
|
|
register: rhel_like
|
|
|
|
- name: Update apt cache (tolerate broken third-party repos)
|
|
ansible.builtin.shell: |
|
|
apt-get update -o Acquire::AllowInsecureRepositories=true -o Acquire::https::Verify-Peer=false -o Acquire::https::Verify-Host=false || true
|
|
when: debian_like.stat.exists
|
|
|
|
- name: Install required packages on Debian/Ubuntu
|
|
ansible.builtin.apt:
|
|
name:
|
|
- sysstat # iostat
|
|
- iotop
|
|
- smartmontools # smartctl
|
|
- nvme-cli
|
|
- mdadm
|
|
- lsscsi
|
|
- sg3-utils
|
|
- pciutils
|
|
state: present
|
|
force_apt_get: yes
|
|
allow_unauthenticated: yes
|
|
when: debian_like.stat.exists
|
|
|
|
- name: Install required packages on RHEL/CentOS
|
|
ansible.builtin.yum:
|
|
name:
|
|
- sysstat
|
|
- iotop
|
|
- smartmontools
|
|
- nvme-cli
|
|
- mdadm
|
|
- lsscsi
|
|
- sg3_utils
|
|
- pciutils
|
|
state: present
|
|
when: rhel_like.stat.exists
|
|
|
|
- name: Enable sysstat service if available
|
|
ansible.builtin.service:
|
|
name: sysstat
|
|
state: started
|
|
enabled: yes
|
|
ignore_errors: yes
|
|
|
|
- name: Create remote dir
|
|
ansible.builtin.file:
|
|
path: "{{ remote_dir }}"
|
|
state: directory
|
|
mode: '0755'
|
|
|
|
- name: Copy agent binary (linux)
|
|
ansible.builtin.copy:
|
|
src: "{{ local_bin_dir }}/agent"
|
|
dest: "{{ remote_dir }}/agent"
|
|
mode: '0755'
|
|
|
|
- name: Copy config
|
|
ansible.builtin.copy:
|
|
src: "{{ local_bin_dir }}/config.yaml"
|
|
dest: "{{ remote_dir }}/config.yaml"
|
|
mode: '0644'
|
|
|
|
- name: Copy collectors directory (no rsync required)
|
|
ansible.builtin.copy:
|
|
src: "{{ local_bin_dir }}/collectors/"
|
|
dest: "{{ remote_dir }}/collectors/"
|
|
mode: '0755'
|
|
directory_mode: '0755'
|
|
|
|
- name: Ensure collectors executable recursively
|
|
ansible.builtin.file:
|
|
path: "{{ remote_dir }}/collectors"
|
|
recurse: yes
|
|
mode: '0755'
|
|
|
|
# - name: Run agent once and capture JSON
|
|
# ansible.builtin.command: "{{ remote_dir }}/agent --once --mode stdout"
|
|
# environment:
|
|
# CONFIG_PATH: "{{ remote_dir }}/config.yaml"
|
|
# register: agent_output
|
|
|
|
# - name: Show agent JSON
|
|
# ansible.builtin.debug:
|
|
# var: agent_output.stdout
|
|
|