60 lines
2.6 KiB
YAML

---
- hosts: all
gather_facts: no
become: true
become_user: root
become_method: sudo
vars:
remote_dir: /opt/sensusagent
local_bin_dir: "{{ LOCAL_BIN_DIR | default('./bin/agent') }}"
tasks:
- name: Ensure remote dir exists
ansible.builtin.raw: "mkdir -p {{ remote_dir }} && chmod 0755 {{ remote_dir }}"
- name: Copy agent binary via scp (from controller)
ansible.builtin.command: >
scp -B -i {{ ansible_ssh_private_key_file | default('~/.ssh/id_rsa') }}
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
{{ local_bin_dir }}/agent {{ ansible_user }}@{{ ansible_host }}:{{ remote_dir }}/agent
delegate_to: localhost
- name: Copy config via scp (from controller)
ansible.builtin.command: >
scp -B -i {{ ansible_ssh_private_key_file | default('~/.ssh/id_rsa') }}
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
{{ local_bin_dir }}/config.yaml {{ ansible_user }}@{{ ansible_host }}:{{ remote_dir }}/config.yaml
delegate_to: localhost
- name: Copy collectors directory via scp -r (from controller)
ansible.builtin.command: >
scp -r -B -i {{ ansible_ssh_private_key_file | default('~/.ssh/id_rsa') }}
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
{{ local_bin_dir }}/collectors {{ ansible_user }}@{{ ansible_host }}:{{ remote_dir }}/
delegate_to: localhost
- name: Ensure collectors are executable
ansible.builtin.raw: "chmod -R 0755 {{ remote_dir }}/collectors 2>/dev/null || true"
- name: Optional deps (Debian/Ubuntu) — ignore errors
ansible.builtin.raw: |
if [ -f /etc/debian_version ]; then \
apt-get update -o Acquire::AllowInsecureRepositories=true -o Acquire::https::Verify-Peer=false -o Acquire::https::Verify-Host=false || true; \
apt-get install -y --no-install-recommends sysstat iotop smartmontools nvme-cli mdadm lsscsi sg3-utils pciutils || true; \
systemctl enable --now sysstat || true; \
fi
ignore_errors: yes
- name: Optional deps (RHEL/CentOS) — ignore errors
ansible.builtin.raw: |
if [ -f /etc/redhat-release ]; then \
yum install -y sysstat iotop smartmontools nvme-cli mdadm lsscsi sg3_utils pciutils || true; \
systemctl enable --now sysstat || true; \
fi
ignore_errors: yes
- name: Show agent version (one-shot) — ignore errors
ansible.builtin.raw: "CONFIG_PATH={{ remote_dir }}/config.yaml {{ remote_dir }}/agent --once --mode stdout >/dev/null 2>&1 || true"
ignore_errors: yes