From 8aefeef485cc66e4b7fcfe3131aa6b36e6e7bee2 Mon Sep 17 00:00:00 2001 From: Gerlando Falauto Date: Mon, 8 Apr 2024 19:06:12 +0200 Subject: [PATCH] wip: install select packages --- plugins/filter/agent.py | 32 ++++++++++++++++++++++++++++++ roles/agent_install/tasks/main.yml | 23 ++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/plugins/filter/agent.py b/plugins/filter/agent.py index 4cb6682bc..9bdb5f057 100644 --- a/plugins/filter/agent.py +++ b/plugins/filter/agent.py @@ -1,4 +1,6 @@ from ansible.utils.display import Display +from ansible.plugins.filter.core import version_compare + def to_agent_driver_type(data): """ Return the desired Sysdig Agent driver type """ try: @@ -24,6 +26,34 @@ def to_agent_version(data): return "latest" +def to_agent_version_pinned(data): + """ Returns True when the agent version to install is pinned, False otherwise + """ + v = to_agent_version(data) + if v and v != '' and v != "latest": + return True + return False + +def to_agent_packages(data): + """ Returns the agent packages to install + """ + pinned = to_agent_version_pinned(data) + older = False + if pinned: + version = to_agent_version(data) + older = version_compare(version, "1.0.0", ">") and version_compare(version, "13.1.0", "<") + if older: + return ["draios-agent"] + else: + dt = to_agent_driver_type(data) + if dt == "legacy_ebpf": + return ["draios-agent-slim"] + elif dt == "kmod": + return ["draios-agent-slim", "draios-agent-legacy-ebpf"] + else: + return ["draios-agent", "draios-agent-slim", "draios-agent-kmodule"] + + def to_agent_install_probe_build_dependencies(data): """ Return true or false depending on if the probe (legacy_ebpf|kmod) build dependencies should be installed @@ -39,5 +69,7 @@ def filters(self): return { "toAgentDriverType": to_agent_driver_type, "toAgentVersion": to_agent_version, + "toAgentVersionPinned": to_agent_version_pinned, + "toAgentPackages": to_agent_packages, "toAgentInstallProbeBuildDependencies": to_agent_install_probe_build_dependencies } diff --git a/roles/agent_install/tasks/main.yml b/roles/agent_install/tasks/main.yml index 9cfa6daf3..62daf670f 100644 --- a/roles/agent_install/tasks/main.yml +++ b/roles/agent_install/tasks/main.yml @@ -3,6 +3,8 @@ ansible.builtin.set_fact: agent_install_version: "{{ configuration | sysdig.agent.toAgentVersion }}" agent_install_driver_type: "{{ configuration | sysdig.agent.toAgentDriverType | lower }}" + agent_install_pinned: "{{ configuration | sysdig.agent.toAgentPinned }}" + agent_install_packages: "{{ configuration | sysdig.agent.toAgentPackages }}" agent_install_probe_build_dependencies: "{{ configuration | sysdig.agent.toAgentInstallProbeBuildDependencies | bool }}" agent_install_deb_repository_url: "{{ configuration | sysdig.agent.toDebUrl | default('https://download.sysdig.com/stable/deb', true) }}" agent_install_deb_repository_gpgkey: "{{ configuration | sysdig.agent.toDebGpgKey | default('https://download.sysdig.com/DRAIOS-GPG-KEY.public', true) }}" @@ -10,6 +12,16 @@ agent_install_rpm_repository_gpgkey: "{{ configuration | sysdig.agent.toRpmGpgKey | default('https://download.sysdig.com/DRAIOS-GPG-KEY.public', true) }}" agent_install_local_forwarder_enabled: "{{ configuration | sysdig.agent.toLocalForwarderEnabled | bool }}" + +- name: Build versions suffix + ansible.builtin.set_fact: + agent_install_version_suffix: "{% if agent_install_pinned %}{% if ansible_pkg_mgr == 'apt' %}={{ agent_install_version }}{% else %}-{{ agent_install_version }}{% endif %}{% endif %}" + +- name: Build package list + ansible.builtin.set_fact: + package_list: "{{ package_list | default([]) + [item.package + agent_install_version_suffix] }}" + loop: "{{ agent_install_packages }}" + - name: Install Sysdig Agent block: - name: Validate Environment @@ -24,18 +36,15 @@ - name: Install Sysdig Agent (latest) ansible.builtin.package: - name: draios-agent + name: "{{ agent_install_package_list }}" state: latest - when: (not agent_install_version) or - (agent_install_version and (agent_install_version == 'latest' or agent_install_version == "")) + when: not agent_install_pinned - name: Install Sysdig Agent (pinned) ansible.builtin.package: - name: "draios-agent{% if agent_install_version != 'latest' %}{% if ansible_pkg_mgr == 'apt' %}={% else %}-{% endif %}{{ agent_install_version }}{% endif %}" + name: "{{ agent_install_package_list }}" state: present - when: - - agent_install_version - - agent_install_version != 'latest' + when: agent_install_pinned - name: Create dragent.yaml file ansible.builtin.template: