Skip to content

Commit

Permalink
wip: install select packages
Browse files Browse the repository at this point in the history
  • Loading branch information
iurly committed Apr 8, 2024
1 parent 8dc772d commit 8aefeef
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
32 changes: 32 additions & 0 deletions plugins/filter/agent.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
}
23 changes: 16 additions & 7 deletions roles/agent_install/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@
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) }}"
agent_install_rpm_repository_url: "{{ configuration | sysdig.agent.toRpmUrl | default('https://download.sysdig.com/stable/rpm/$basearch', true) }}"
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
Expand All @@ -24,18 +36,15 @@

- name: Install Sysdig Agent (latest)

Check warning on line 37 in roles/agent_install/tasks/main.yml

View workflow job for this annotation

GitHub Actions / lint-branch

package-latest

Package installs should not use 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:
Expand Down

0 comments on commit 8aefeef

Please sign in to comment.