added multica agent hosts
This commit is contained in:
1 parent
5559cd425d
commit
01cd7b8d1e
32 files changed
+2636
-417
No files matched your search
@@ -0,0 +1,42 @@
|
||||
---
|
||||
# Resolve where the binary ACTUALLY is before linking to it.
|
||||
#
|
||||
# The npm path used to link unconditionally from multica_npm_prefix. When the
|
||||
# CLI was already installed by some other means — a distro package, a vendor
|
||||
# installer, a previous hand-rollout — nothing was installed at that prefix and
|
||||
# `file: state=link force=true` happily created a DANGLING symlink in
|
||||
# /usr/local/bin. PATH resolution skips a dangling link, so discovery still
|
||||
# worked by luck wherever the real binary was already on systemd's PATH, and
|
||||
# the role's actual guarantee silently did not hold.
|
||||
- name: "Agents | Resolve the installed binary | {{ _agent_key }}"
|
||||
ansible.builtin.command:
|
||||
argv: ["/bin/sh", "-c", "command -v {{ _agent.binary }}"]
|
||||
become: true
|
||||
become_user: "{{ multica_user }}"
|
||||
environment: "{{ _multica_user_env }}"
|
||||
register: _agent_which
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
check_mode: false
|
||||
|
||||
- name: "Agents | Require the binary to be resolvable | {{ _agent_key }}"
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- _agent_which.rc == 0
|
||||
- (_agent_which.stdout | trim) | length > 0
|
||||
fail_msg: >-
|
||||
{{ _agent.binary }} is not on {{ multica_user }}'s PATH after the install
|
||||
step. The daemon discovers provider CLIs by PATH, so it would register no
|
||||
{{ _agent_key }} runtime.
|
||||
quiet: true
|
||||
|
||||
# Linking the resolved path also repairs a dangling link left by an older run:
|
||||
# `command -v` skips the broken link, so this overwrites it with a working one.
|
||||
- name: "Agents | Link onto the default PATH | {{ _agent_key }}"
|
||||
ansible.builtin.file:
|
||||
src: "{{ _agent_which.stdout | trim }}"
|
||||
dest: "{{ multica_install_dir }}/{{ _agent.binary }}"
|
||||
state: link
|
||||
force: true
|
||||
become: true
|
||||
when: (_agent_which.stdout | trim) != (multica_install_dir ~ '/' ~ _agent.binary)
|
||||
@@ -0,0 +1,46 @@
|
||||
---
|
||||
- name: "Agents | Resolve catalog entry | {{ _agent_key }}"
|
||||
ansible.builtin.set_fact:
|
||||
_agent: "{{ multica_agent_cli_catalog[_agent_key] }}"
|
||||
|
||||
- name: "Agents | Read the installed version | {{ _agent_key }}"
|
||||
ansible.builtin.command:
|
||||
argv: ["/bin/sh", "-c", "command -v {{ _agent.binary }} >/dev/null 2>&1 && {{ _agent.version_command }}"]
|
||||
become: true
|
||||
become_user: "{{ multica_user }}"
|
||||
environment: "{{ _multica_user_env }}"
|
||||
register: _agent_installed
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
check_mode: false
|
||||
|
||||
# Version formats differ per CLI ("2.1.304 (Claude Code)", "Hermes Agent
|
||||
# v0.21.5+..."), so this matches the pinned version anywhere in the output —
|
||||
# but on a version-component boundary. A plain substring test would accept
|
||||
# 2.1.3045 for a pin of 2.1.304, and silently never upgrade.
|
||||
- name: "Agents | Decide whether an install is needed | {{ _agent_key }}"
|
||||
ansible.builtin.set_fact:
|
||||
_agent_needs_install: >-
|
||||
{{ _agent_installed.rc != 0
|
||||
or (_agent.package_version | default('') | length > 0
|
||||
and not ((_agent_installed.stdout | default('')) is search(
|
||||
'(^|[^0-9.])' ~ (_agent.package_version | regex_escape) ~ '([^0-9.]|$)'))) }}
|
||||
|
||||
- name: "Agents | Install via npm as the daemon user | {{ _agent_key }}"
|
||||
ansible.builtin.command:
|
||||
argv:
|
||||
- "{{ multica_install_dir }}/npm"
|
||||
- install
|
||||
- --global
|
||||
- --no-fund
|
||||
- --no-audit
|
||||
- "{{ _agent.package }}{{ ('@' ~ _agent.package_version) if _agent.package_version | default('') | length > 0 else '' }}"
|
||||
become: true
|
||||
become_user: "{{ multica_user }}"
|
||||
environment: "{{ _multica_user_env }}"
|
||||
when: _agent_needs_install | bool
|
||||
changed_when: true
|
||||
notify: restart multica daemon
|
||||
|
||||
- name: "Agents | Resolve and link onto the default PATH | {{ _agent_key }}"
|
||||
ansible.builtin.include_tasks: _link.yml
|
||||
@@ -0,0 +1,53 @@
|
||||
---
|
||||
- name: "Agents | Resolve catalog entry | {{ _agent_key }}"
|
||||
ansible.builtin.set_fact:
|
||||
_agent: "{{ multica_agent_cli_catalog[_agent_key] }}"
|
||||
|
||||
- name: "Agents | Read the installed version | {{ _agent_key }}"
|
||||
ansible.builtin.command:
|
||||
argv: ["/bin/sh", "-c", "command -v {{ _agent.binary }} >/dev/null 2>&1 && {{ _agent.version_command }}"]
|
||||
become: true
|
||||
become_user: "{{ multica_user }}"
|
||||
environment: "{{ _multica_user_env }}"
|
||||
register: _agent_installed
|
||||
changed_when: false
|
||||
failed_when: false
|
||||
check_mode: false
|
||||
|
||||
# Piping a vendor script into a shell is a supply-chain decision, so the role
|
||||
# refuses rather than making it quietly on the operator's behalf.
|
||||
- name: "Agents | Refuse to run a remote installer unless allowed | {{ _agent_key }}"
|
||||
ansible.builtin.fail:
|
||||
msg: >-
|
||||
{{ _agent_key }} installs by executing {{ _agent.install_url }}.
|
||||
Set multica_allow_remote_install_scripts: true to permit that, vendor the
|
||||
installer yourself, or drop {{ _agent_key }} from multica_agent_clis.
|
||||
when:
|
||||
- _agent_installed.rc != 0
|
||||
- not (multica_allow_remote_install_scripts | bool)
|
||||
|
||||
- name: "Agents | Install via the vendor script | {{ _agent_key }}"
|
||||
when:
|
||||
- _agent_installed.rc != 0
|
||||
- multica_allow_remote_install_scripts | bool
|
||||
block:
|
||||
- name: "Agents | Fetch the installer | {{ _agent_key }}"
|
||||
ansible.builtin.get_url:
|
||||
url: "{{ _agent.install_url }}"
|
||||
dest: "{{ multica_user_home }}/.cache/{{ _agent_key }}-install.sh"
|
||||
owner: "{{ multica_user }}"
|
||||
group: "{{ multica_group }}"
|
||||
mode: "0700"
|
||||
become: true
|
||||
|
||||
- name: "Agents | Run it as the daemon user | {{ _agent_key }}"
|
||||
ansible.builtin.command:
|
||||
argv: ["/bin/bash", "{{ multica_user_home }}/.cache/{{ _agent_key }}-install.sh"]
|
||||
become: true
|
||||
become_user: "{{ multica_user }}"
|
||||
environment: "{{ _multica_user_env }}"
|
||||
changed_when: true
|
||||
notify: restart multica daemon
|
||||
|
||||
- name: "Agents | Resolve and link onto the default PATH | {{ _agent_key }}"
|
||||
ansible.builtin.include_tasks: _link.yml
|
||||
Reference in new issue
Block a user