From 5ac09e72e7fd8d3593e2598d896689f52708869d Mon Sep 17 00:00:00 2001 From: Pythyu Date: Tue, 4 Apr 2023 10:53:40 +0200 Subject: [PATCH 1/6] feat(macOS): check if user and group exists --- tasks/pkg-macos.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tasks/pkg-macos.yml b/tasks/pkg-macos.yml index fb17f24f..12174b3c 100644 --- a/tasks/pkg-macos.yml +++ b/tasks/pkg-macos.yml @@ -6,6 +6,26 @@ msg: "The Datadog ansible role does not currently support Agent 5 on macOS" when: datadog_agent_major_version|int == 5 +- name: Check if user doesn't exist + command: id -u "{{ datadog_macos_user }}" >/dev/null 2>&1 + register: mac_user_check + ignore_errors: true + +- name: Fail if user doesn't exist + fail: + msg: "The Datadog ansible role wasn't able to find the user : {{ datadog_macos_user }}" + when: mac_user_check|failed + +- name: Check if group doesn't exist + command: dscacheutil -q group | grep "name:" | awk '{print $2}' | grep -w "{{ macos_user_group.stdout }}" >/dev/null 2>&1 + register: mac_group_check + ignore_errors: true + +- name: Fail if group doesn't exist + fail: + msg: "The Datadog ansible role wasn't able to find the group : {{ macos_user_group.stdout }}" + when: mac_group_check|failed + - include_tasks: pkg-macos/macos_agent_latest.yml when: (not datadog_skip_install) and (datadog_agent_macos_version is not defined) From 9913ab2f288f5253c0120221fcb21fe20dcd0232 Mon Sep 17 00:00:00 2001 From: Pythyu Date: Tue, 4 Apr 2023 16:44:45 +0200 Subject: [PATCH 2/6] update(pkg-macros): fix previous errors + rework group handling --- tasks/pkg-macos.yml | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tasks/pkg-macos.yml b/tasks/pkg-macos.yml index 12174b3c..17f1b19d 100644 --- a/tasks/pkg-macos.yml +++ b/tasks/pkg-macos.yml @@ -7,24 +7,30 @@ when: datadog_agent_major_version|int == 5 - name: Check if user doesn't exist - command: id -u "{{ datadog_macos_user }}" >/dev/null 2>&1 + command: id -u "{{ datadog_macos_user }}" register: mac_user_check ignore_errors: true - name: Fail if user doesn't exist fail: msg: "The Datadog ansible role wasn't able to find the user : {{ datadog_macos_user }}" - when: mac_user_check|failed + when: mac_user_check.rc != 0 + +- name: Get user group data gid + shell: + cmd : 'dscacheutil -q user -a name "{{ datadog_macos_user }}" | grep "gid" | grep -oE "[0-9]+"' + register: macos_group_data_gid - name: Check if group doesn't exist - command: dscacheutil -q group | grep "name:" | awk '{print $2}' | grep -w "{{ macos_user_group.stdout }}" >/dev/null 2>&1 + shell: + cmd: "dscacheutil -q group -a gid {{ macos_group_data_gid }} | grep '^name: ' | awk '{ print $2 }'" register: mac_group_check ignore_errors: true - name: Fail if group doesn't exist fail: - msg: "The Datadog ansible role wasn't able to find the group : {{ macos_user_group.stdout }}" - when: mac_group_check|failed + msg: "The Datadog ansible role wasn't able to find the group : {{ macos_group_data_gid }}" + when: mac_group_check.rc != 0 - include_tasks: pkg-macos/macos_agent_latest.yml when: (not datadog_skip_install) and (datadog_agent_macos_version is not defined) From aa154a358839f157bed275b78cad72ea9370a6c3 Mon Sep 17 00:00:00 2001 From: Pythyu Date: Tue, 4 Apr 2023 16:54:53 +0200 Subject: [PATCH 3/6] fix(pkg-macos): fix no-changed-when linter issues --- tasks/pkg-macos.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tasks/pkg-macos.yml b/tasks/pkg-macos.yml index 17f1b19d..777377fb 100644 --- a/tasks/pkg-macos.yml +++ b/tasks/pkg-macos.yml @@ -6,9 +6,10 @@ msg: "The Datadog ansible role does not currently support Agent 5 on macOS" when: datadog_agent_major_version|int == 5 -- name: Check if user doesn't exist +- name: Check if user exist command: id -u "{{ datadog_macos_user }}" register: mac_user_check + changed_when: false ignore_errors: true - name: Fail if user doesn't exist @@ -19,12 +20,14 @@ - name: Get user group data gid shell: cmd : 'dscacheutil -q user -a name "{{ datadog_macos_user }}" | grep "gid" | grep -oE "[0-9]+"' + changed_when: false register: macos_group_data_gid -- name: Check if group doesn't exist +- name: Check if group exist shell: cmd: "dscacheutil -q group -a gid {{ macos_group_data_gid }} | grep '^name: ' | awk '{ print $2 }'" register: mac_group_check + changed_when: false ignore_errors: true - name: Fail if group doesn't exist From c4914adca28666743933e47ee0a55b61e4ac3d6e Mon Sep 17 00:00:00 2001 From: Pythyu Date: Thu, 6 Apr 2023 10:28:08 +0200 Subject: [PATCH 4/6] useless(pkg-macos): removed group check --- tasks/pkg-macos.yml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/tasks/pkg-macos.yml b/tasks/pkg-macos.yml index 777377fb..b3885e10 100644 --- a/tasks/pkg-macos.yml +++ b/tasks/pkg-macos.yml @@ -17,24 +17,6 @@ msg: "The Datadog ansible role wasn't able to find the user : {{ datadog_macos_user }}" when: mac_user_check.rc != 0 -- name: Get user group data gid - shell: - cmd : 'dscacheutil -q user -a name "{{ datadog_macos_user }}" | grep "gid" | grep -oE "[0-9]+"' - changed_when: false - register: macos_group_data_gid - -- name: Check if group exist - shell: - cmd: "dscacheutil -q group -a gid {{ macos_group_data_gid }} | grep '^name: ' | awk '{ print $2 }'" - register: mac_group_check - changed_when: false - ignore_errors: true - -- name: Fail if group doesn't exist - fail: - msg: "The Datadog ansible role wasn't able to find the group : {{ macos_group_data_gid }}" - when: mac_group_check.rc != 0 - - include_tasks: pkg-macos/macos_agent_latest.yml when: (not datadog_skip_install) and (datadog_agent_macos_version is not defined) From 0802bf1f9e4172b92cc8fe552db0ddc835c58b05 Mon Sep 17 00:00:00 2001 From: Marethyu <45374460+Pythyu@users.noreply.github.com> Date: Thu, 6 Apr 2023 10:40:00 +0200 Subject: [PATCH 5/6] Update tasks/pkg-macos.yml Co-authored-by: Slavek Kabrda --- tasks/pkg-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/pkg-macos.yml b/tasks/pkg-macos.yml index b3885e10..004e3faf 100644 --- a/tasks/pkg-macos.yml +++ b/tasks/pkg-macos.yml @@ -6,7 +6,7 @@ msg: "The Datadog ansible role does not currently support Agent 5 on macOS" when: datadog_agent_major_version|int == 5 -- name: Check if user exist +- name: Check if the macOS user for Agent service exists command: id -u "{{ datadog_macos_user }}" register: mac_user_check changed_when: false From 3e28899a07aff78c226397ea8e30226be5f61aad Mon Sep 17 00:00:00 2001 From: Marethyu <45374460+Pythyu@users.noreply.github.com> Date: Thu, 6 Apr 2023 10:40:07 +0200 Subject: [PATCH 6/6] Update tasks/pkg-macos.yml Co-authored-by: Slavek Kabrda --- tasks/pkg-macos.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/pkg-macos.yml b/tasks/pkg-macos.yml index 004e3faf..191003f4 100644 --- a/tasks/pkg-macos.yml +++ b/tasks/pkg-macos.yml @@ -12,7 +12,7 @@ changed_when: false ignore_errors: true -- name: Fail if user doesn't exist +- name: Fail if the macOS user for Agent service doesn't exist fail: msg: "The Datadog ansible role wasn't able to find the user : {{ datadog_macos_user }}" when: mac_user_check.rc != 0