Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macOS support #437

Merged
merged 5 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ commands:
jinja2_native:
type: string
default: "false"
inventory:
type: string
default: "ci.ini"
steps:
- run: ANSIBLE_JINJA2_NATIVE="<<parameters.jinja2_native>>" ansible-playbook -i ./ci_test/inventory/ci.ini "./ci_test/install_agent_<<parameters.version>>.yaml" -e 'ansible_python_interpreter=/usr/bin/<<parameters.python>>'
- run: ANSIBLE_JINJA2_NATIVE="<<parameters.jinja2_native>>" ansible-playbook -i ./ci_test/inventory/<<parameters.inventory>> "./ci_test/install_agent_<<parameters.version>>.yaml" -e 'ansible_python_interpreter=/usr/bin/<<parameters.python>>'
- run: datadog-agent version

test_install_no_manage_config:
Expand Down Expand Up @@ -94,6 +97,23 @@ commands:
python: "<<parameters.python>>"
jinja2_native: "<<parameters.jinja2_native>>"

test_agent_install_macos:
parameters:
version:
type: string
python:
type: string
jinja2_native:
type: string
default: "false"
steps:
- checkout
- install_agent:
version: "<<parameters.version>>"
python: "<<parameters.python>>"
jinja2_native: "<<parameters.jinja2_native>>"
inventory: "ci_macos.ini"

jobs:
ansible_lint:
docker:
Expand Down Expand Up @@ -162,6 +182,32 @@ jobs:
version: "<<parameters.agent_version>>"
python: "<<parameters.python>>"

test_install_macos:
parameters:
ansible_version:
type: string
agent_version:
type: string
python:
type: string
jinja2_native:
type: string
default: "false"
macos:
xcode: 13.3.0
steps:
- checkout
- run:
name: Install Python3
command: brew install python3
- run:
name: Install Ansible
command: pip3 install ansible~=<<parameters.ansible_version>>
- test_agent_install_macos:
version: "<<parameters.agent_version>>"
python: "<<parameters.python>>"
jinja2_native: "<<parameters.jinja2_native>>"

workflows:
version: 2
test_datadog_role:
Expand Down Expand Up @@ -244,3 +290,10 @@ workflows:
agent_version: ["6", "7"]
os: ["amazonlinux2"]
python: ["python3"]

- test_install_macos:
matrix:
parameters:
ansible_version: ["2.8", "2.9", "2.10", "3.4", "4.10"]
agent_version: ["6_macos", "7_macos"]
python: ["python3"]
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
*.retry
.venv

Expand Down
97 changes: 56 additions & 41 deletions README.md

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions ci_test/install_agent_6_macos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---

- hosts: all
roles:
- { role: '/Users/distiller/project/' }
vars:
datadog_api_key: "11111111111111111111111111111111"
datadog_enabled: false
datadog_agent_major_version: 6
# avoid checking that the agent is stopped for centos
datadog_skip_running_check: true
datadog_config:
tags: "mytag0, mytag1"
log_level: INFO
apm_enabled: "true" # has to be set as a string
datadog_config_ex:
trace.config:
env: dev
trace.concentrator:
extra_aggregators: version
datadog_checks:
process:
init_config:
instances:
- name: agent
search_string: ['agent', 'sshd' ]
28 changes: 28 additions & 0 deletions ci_test/install_agent_7_macos.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---

- hosts: all
roles:
- { role: '/Users/distiller/project/' }
vars:
datadog_api_key: "11111111111111111111111111111111"
datadog_enabled: false
datadog_agent_major_version: 7
# avoid checking that the agent is stopped for centos
datadog_skip_running_check: true
datadog_config:
tags: "mytag0, mytag1"
log_level: INFO
apm_enabled: "true" # has to be set as a string
datadog_config_ex:
trace.config:
env: dev
trace.concentrator:
extra_aggregators: version
runtime_security_config:
enabled: true
datadog_checks:
process:
init_config:
instances:
- name: agent
search_string: ['agent', 'sshd' ]
2 changes: 2 additions & 0 deletions ci_test/inventory/ci_macos.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[test]
127.0.0.1 ansible_connection=local ansible_user=distiller
26 changes: 25 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ datadog_group: dd-agent
# agent integration variables
integration_command_user_linux: "dd-agent"
integration_command_user_windows: "administrator"
integration_command_user_macos: "dd-agent"
datadog_agent_binary_path_linux: /opt/datadog-agent/bin/agent/agent
datadog_agent_binary_path_windows: "C:\\Program Files\\Datadog\\Datadog Agent\\bin\\agent.exe"
datadog_agent_binary_path_macos: "/opt/datadog-agent/bin/agent/agent"

# list of additional groups for datadog_user
datadog_additional_groups: {}
Expand All @@ -57,7 +59,6 @@ datadog_agent_version: ""
# Default Package name for APT and RPM installs - can override in playbook for IOT Agent
datadog_agent_flavor: "datadog-agent"


# Default apt repo and keyserver

# By default, the role uses the official apt Datadog repository for the chosen major version
Expand Down Expand Up @@ -189,3 +190,26 @@ datadog_agent7_yum_repo: "https://yum.datadoghq.com/stable/7/{{ ansible_facts.ar
datadog_agent5_zypper_repo: "https://yum.datadoghq.com/suse/rpm/{{ ansible_facts.architecture }}"
datadog_agent6_zypper_repo: "https://yum.datadoghq.com/suse/stable/6/{{ ansible_facts.architecture }}"
datadog_agent7_zypper_repo: "https://yum.datadoghq.com/suse/stable/7/{{ ansible_facts.architecture }}"

# Default macOS latest dmg package URL

# By default, will use the official latest dmg package for the chosen major version.
# Use the datadog_macos_download_url option to override the dmg package used.
datadog_macos_download_url: ""

# The default dmg package for each major Agent version is specified in the following variables.
# These variables are for internal use only, do not modify them.
datadog_macos_agent6_latest_url: "https://s3.amazonaws.com/dd-agent/datadog-agent-6-latest.dmg"
datadog_macos_agent7_latest_url: "https://s3.amazonaws.com/dd-agent/datadog-agent-7-latest.dmg"

# If datadog_agent_version is set, the role will use the following url prefix instead, and append the version number to it
# in order to get the full url to the dmg package.
datadog_macos_versioned_url: "https://s3.amazonaws.com/dd-agent/datadog-agent"

datadog_macos_user: "{{ ansible_user }}"
datadog_macos_service_name: "com.datadoghq.agent"
datadog_macos_user_plist_file_path: "Library/LaunchAgents/{{ datadog_macos_service_name }}.plist"
datadog_macos_system_plist_file_path: "/Library/LaunchDaemons/{{ datadog_macos_service_name }}.plist"
datadog_macos_etc_dir: "/opt/datadog-agent/etc"
datadog_macos_logs_dir: "/opt/datadog-agent/logs"
datadog_macos_run_dir: "/opt/datadog-agent/run"
27 changes: 27 additions & 0 deletions handlers/main-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
# This file doesn't actually contain "handlers" in the Ansible sense: when running
# our role, Ansible only loads the contents of handlers/main.yml as handlers.
# However, this is here because this is a "handler-like" task that is dynamically
# included by a handler task in handlers/main.yml.

# NOTE: We don't use bootout/bootstrap here, because bootout can't wait for the operation
# to finish and if it's in progress for a longer time, bootstrap fails. We use the old
# unload/load combo because they actually wait.
- name: Unload datadog-agent service
command: "launchctl unload -wF {{ datadog_macos_system_plist_file_path }}"
become: yes
check_mode: no
when: datadog_enabled and not ansible_check_mode and ansible_facts.os_family == "Darwin"

- name: Load datadog-agent service
command: "launchctl load -wF {{ datadog_macos_system_plist_file_path }}"
become: yes
check_mode: no
when: datadog_enabled and not ansible_check_mode and ansible_facts.os_family == "Darwin"

- name: Restart datadog-agent service
command: "launchctl kickstart -k system/{{ datadog_macos_service_name }}"
become: yes
register: command_result
check_mode: no
when: datadog_enabled and not ansible_check_mode and ansible_facts.os_family == "Darwin"
12 changes: 10 additions & 2 deletions handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
service:
name: datadog-agent-sysprobe
state: restarted
when: datadog_enabled and datadog_sysprobe_enabled and not ansible_check_mode and not ansible_facts.os_family == "Windows"
when: datadog_enabled and datadog_sysprobe_enabled and not ansible_check_mode and not ansible_facts.os_family == "Windows" and not ansible_facts.os_family == "Darwin"

- name: restart datadog-agent
service:
name: datadog-agent
state: restarted
when: datadog_enabled and not ansible_check_mode and not ansible_facts.os_family == "Windows"
when: datadog_enabled and not ansible_check_mode and not ansible_facts.os_family == "Windows" and not ansible_facts.os_family == "Darwin"

# We can't add the Windows Agent service restart handler directly here because that makes the role require
# the ansible.windows collection on all platforms. We only want it to be needed on Windows.
Expand All @@ -21,3 +21,11 @@
# (which depends on ansible.windows), and runs it, triggering the Windows Agent restart.
- name: restart datadog-agent-win
include_tasks: handlers/main-win.yml

# When needed, our macOS tasks call this handler to require a
# macOS Agent restart (through notify: restart datadog-agent-macos).
# When notified, the below handler is executed at the end of the playbook run.
# The include_tasks loads the handlers/main-macos.yml file, which contains the real service restart task
# and runs it, triggering the macOS Agent restart.
- name: restart datadog-agent-macos
include_tasks: handlers/main-macos.yml
3 changes: 3 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ galaxy_info:
- 2012R2
- 2016
- 2019
- name: Darwin
versions:
- any
galaxy_tags:
- monitoring
dependencies: []
91 changes: 91 additions & 0 deletions tasks/_agent-linux-macos-shared.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
- name: Create Datadog agent config directory
file:
dest: "{{ _dd_config_dir }}"
state: directory
mode: 0755
owner: "{{ _dd_user }}"
group: "{{ _dd_group }}"
when: datadog_manage_config

- name: Create main Datadog agent configuration file
template:
src: datadog.yaml.j2
dest: "{{ _dd_config_dir }}/datadog.yaml"
mode: 0640
owner: "{{ _dd_user }}"
group: "{{ _dd_group }}"
when: datadog_manage_config
notify: "{{ _dd_notify_agent }}"

- name: Register all checks directories present in datadog
find:
paths: "{{ _dd_config_dir }}/conf.d/"
patterns:
- "*.d"
file_type: directory
register: datadog_conf_directories
when: datadog_manage_config and (datadog_disable_untracked_checks or datadog_disable_default_checks)

- name: Delete checks not present in datadog_tracked_checks
file:
path: "{{ _dd_config_dir }}/conf.d/{{ item }}.d/conf.yaml"
state: absent
loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}"
when: datadog_manage_config and datadog_disable_untracked_checks and item not in datadog_tracked_checks
notify: "{{ _dd_notify_agent }}"

- name: Delete all default checks
file:
path: "{{ _dd_config_dir }}/conf.d/{{ item }}.d/conf.yaml.default"
state: absent
loop: "{{ datadog_conf_directories.files | map(attribute='path') | list | map('basename') | list | map('regex_replace', '^(.*).d$', '\\1') | list }}"
when: datadog_manage_config and datadog_disable_default_checks and item not in datadog_tracked_checks
notify: "{{ _dd_notify_agent }}"

- name: Ensure configuration directories are present for each Datadog check
file:
dest: "{{ _dd_config_dir }}/conf.d/{{ item }}.d"
state: directory
owner: "{{ _dd_user }}"
group: "{{ _dd_group }}"
mode: 0755
with_items: '{{ datadog_checks|list }}'
when: datadog_manage_config

- name: Create a configuration file for each Datadog check
template:
src: checks.yaml.j2
dest: "{{ _dd_config_dir }}/conf.d/{{ item }}.d/conf.yaml"
mode: 0640
owner: "{{ _dd_user }}"
group: "{{ _dd_group }}"
with_items: "{{ datadog_checks|list }}"
when: datadog_manage_config
notify: "{{ _dd_notify_agent }}"

- name: Remove old configuration file for each Datadog check
file:
dest: "{{ _dd_config_dir }}/conf.d/{{ item }}.yaml"
state: absent
with_items: "{{ datadog_checks|list }}"
when: datadog_manage_config
notify: "{{ _dd_notify_agent }}"

- name: Create custom check file for each custom check
copy:
src: "{{ datadog_custom_checks[item] }}"
dest: "{{ _dd_config_dir }}/checks.d/{{ item }}.py"
mode: 0755
owner: "{{ _dd_user }}"
group: "{{ _dd_group }}"
with_items: "{{ datadog_custom_checks|list }}"
notify: "{{ _dd_notify_agent }}"

- name: Create installation information file
template:
src: install_info.j2
dest: "{{ _dd_config_dir }}/install_info"
owner: "{{ _dd_user }}"
group: "{{ _dd_group }}"
mode: 0644
Loading