--- - 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') }}" tmp_upload_dir: "/tmp/sensusagent_upload" tasks: - name: Ensure remote dir exists ansible.builtin.raw: "mkdir -p {{ remote_dir }} && chmod 0755 {{ remote_dir }}" - name: Ensure tmp upload dir exists and writable by user ansible.builtin.raw: "mkdir -p {{ tmp_upload_dir }} && chmod 0777 {{ tmp_upload_dir }}" - name: Copy agent binary via scp (from controller) to tmp 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 }}:{{ tmp_upload_dir }}/agent delegate_to: localhost - name: Generate config.yaml from template ansible.builtin.template: src: ../templates/config.yaml.j2 dest: "{{ tmp_upload_dir }}/config.yaml" mode: '0644' delegate_to: localhost run_once: true - name: Copy collectors directory via scp -r (from controller) to tmp 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 }}:{{ tmp_upload_dir }}/ delegate_to: localhost - name: Move uploaded files into place as root and set permissions ansible.builtin.raw: | install -m 0755 {{ tmp_upload_dir }}/agent {{ remote_dir }}/agent && \ install -m 0644 {{ tmp_upload_dir }}/config.yaml {{ remote_dir }}/config.yaml && \ rm -rf {{ remote_dir }}/collectors && mkdir -p {{ remote_dir }}/collectors && \ cp -a {{ tmp_upload_dir }}/collectors/. {{ remote_dir }}/collectors/ && \ chmod -R 0755 {{ remote_dir }}/collectors ignore_errors: no - 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 lm-sensors ipmitool jq || 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 lm_sensors ipmitool jq || 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