Skip to content

Commit 7f96ac9

Browse files
committed
Learn Editor: Update linux-install-with-ansible.md
1 parent 81d3238 commit 7f96ac9

File tree

1 file changed

+178
-38
lines changed

1 file changed

+178
-38
lines changed

defender-endpoint/linux-install-with-ansible.md

Lines changed: 178 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,19 @@ This article describes how to deploy Defender for Endpoint on Linux using Ansibl
3434

3535
[!INCLUDE [Microsoft Defender for Endpoint third-party tool support](../includes/support.md)]
3636

37-
## Prerequisites and system requirements
37+
## Introduction
38+
39+
Deploy Microsoft Defender for Endpoint on Linux Servers using Ansible to automate the deployment process for machines at scale. Following are the two methods to automate.
40+
41+
1.        Using installer script (recommended)
42+
43+
This method greatly simplifies the automation process and helps to install the MDE agent  as well as onboard the device to security portal using just a few steps without having to configure for different distros separately.
44+
45+
2.        Manually configuring repositories for each distro
46+
47+
This method allows to automate the deployment process by manually configuring repositories, installing the agent and onboarding the device for each distro. This method  gives more granular control over the deployment process.
48+
49+
## Prerequisites and system requirements applicable to both the Methods
3850

3951
Before you get started, see [the main Defender for Endpoint on Linux page](microsoft-defender-endpoint-linux.md) for a description of prerequisites and system requirements for the current software version.
4052

@@ -60,7 +72,7 @@ In addition, for Ansible deployment, you need to be familiar with Ansible admini
6072
ansible -m ping all
6173
```
6274

63-
## Download the onboarding package
75+
## Download the onboarding package applicable to both the methods
6476

6577
Download the onboarding package from Microsoft Defender portal.
6678

@@ -89,43 +101,171 @@ Download the onboarding package from Microsoft Defender portal.
89101
inflating: mdatp_onboard.json
90102
```
91103

92-
## Create Ansible YAML files
104+
## Deploy MDE using mde_installer.sh with Ansible
93105

94-
Create a subtask or role files that contribute to a playbook or task.
106+
Follow the steps below after [downloading the onboarding package]() and completing [pre-requisites]() to deploy MDE using installer bash script
95107

96-
- Create the onboarding task, `onboarding_setup.yml`:
108+
### Download the installer bash script
97109

98-
```bash
99-
- name: Create MDATP directories
100-
file:
101-
path: /etc/opt/microsoft/mdatp/
102-
recurse: true
103-
state: directory
104-
mode: 0755
105-
owner: root
106-
group: root
107-
108-
- name: Register mdatp_onboard.json
109-
stat:
110-
path: /etc/opt/microsoft/mdatp/mdatp_onboard.json
111-
register: mdatp_onboard
112-
113-
- name: Extract WindowsDefenderATPOnboardingPackage.zip into /etc/opt/microsoft/mdatp
114-
unarchive:
115-
src: WindowsDefenderATPOnboardingPackage.zip
116-
dest: /etc/opt/microsoft/mdatp
117-
mode: 0600
118-
owner: root
119-
group: root
120-
when: not mdatp_onboard.stat.exists
121-
```
110+
Pull the [installer bash script](https://github.com/microsoft/mdatp-xplat/tree/master/linux/installation) from Microsoft Github Repository or use the below command to download
111+
112+
```bash
113+
wget https://raw.githubusercontent.com/microsoft/mdatp-xplat/refs/heads/master/linux/installation/mde_installer.sh
114+
```
115+
116+
### Create Ansible YAML files
117+
118+
Create installation YAML file
119+
120+
```bash
121+
- name: Install and Onboard MDE
122+
hosts: servers
123+
tasks:
124+
- name: Create a directory if it does not exist
125+
ansible.builtin.file:
126+
path: /tmp/mde_install
127+
state: directory
128+
mode: '0755'
129+
130+
- name: Copy Onboarding script
131+
ansible.builtin.copy:
132+
src: "{{ onboarding_script }}"
133+
dest: /tmp/mde_install/mdatp_onboard.json
134+
- name: Install MDE on host
135+
ansible.builtin.script: "{{ mde_installer_script }} --install --channel {{ channel | default('insiders-fast') }} --onboard /tmp/mde_install/mdatp_onboard.json"
136+
register: script_output
137+
args:
138+
executable: sudo
139+
140+
- name: Display the installation output
141+
debug:
142+
msg: "Return code [{{ script_output.rc }}] {{ script_output.stdout }}"
143+
144+
- name: Display any installation errors
145+
debug:
146+
msg: "{{ script_output.stderr }}"
147+
148+
```
149+
150+
### Deploy MDE using the above playbook using the command
151+
152+
Replace the corresponding paths and channel in the below command as per your requirement
153+
154+
```bash
155+
ansible-playbook -i /etc/ansible/hosts /etc/ansible/playbooks/install_mdatp.yml --extra-vars "onboarding_script=<path to mdatp_onboard.json > mde_installer_script=<path to mde_installer.sh> channel=<channel to deploy for: insiders-fast / insiders-slow / prod> "
156+
157+
158+
```
159+
160+
### Verify deployment
161+
162+
a.     Go to __[Microsoft Defender Security Portal]()__ inventory. It might take 5-20 mins for the device to show up on the portal.
163+
164+
b.    Perform the below post-installation checks which includes checks like health, connectivity, AV/EDR detection tests to ensure successful deployment and working of MDE
165+
166+
```bash
167+
168+
- name: Run post-installation basic MDE test
169+
hosts: myhosts
170+
tasks:
171+
- name: Check health
172+
ansible.builtin.command: mdatp health --field healthy
173+
register: health_status
174+
175+
- name: MDE health test failed
176+
fail: msg="MDE is not healthy. health status => \n{{ health_status.stdout }}\nMDE deployment not complete"
177+
when: health_status.stdout != "true"
178+
179+
- name: Run connectivity test
180+
ansible.builtin.command: mdatp connectivity test
181+
register: connectivity_status
182+
183+
- name: Connectivity failed
184+
fail: msg="Connectivity failed. Connectivity result => \n{{ connectivity_status.stdout }}\n MDE deployment not complete"
185+
when: connectivity_status.rc != 0
186+
187+
- name: Check RTP status
188+
ansible.builtin.command: mdatp health --field real_time_protection_enabled
189+
register: rtp_status
190+
191+
- name: Enable RTP
192+
ansible.builtin.command: mdatp config real-time-protection --value enabled
193+
become: yes
194+
become_user: root
195+
when: rtp_status.stdout != "true"
196+
197+
- name: Pause for 5 second to enable RTP
198+
ansible.builtin.pause:
199+
seconds: 5
200+
201+
- name: Download EICAR
202+
ansible.builtin.get_url:
203+
url: https://secure.eicar.org/eicar.com.txt
204+
dest: /tmp/eicar.com.txt
205+
206+
- name: Pause for 5 second to detect eicar
207+
ansible.builtin.pause:
208+
seconds: 5
209+
210+
- name: Check for EICAR file
211+
stat: path=/tmp/eicar.com.txt
212+
register: eicar_test
213+
214+
- name: EICAR test failed
215+
fail: msg="EICAR file not deleted. MDE deployment not complete"
216+
when: eicar_test.stat.exists
217+
218+
- name: MDE Deployed
219+
debug:
220+
msg: "MDE succesfully deployed"
221+
222+
223+
```
224+
225+
### How to uninstall Microsoft Defender for Endpoint on Linux Servers
226+
227+
Create uninstallation YAML file (eg: /etc/ansible/playbooks/uninstall_mdatp.yml)  which uses mde_installer.sh
228+
229+
```bash
230+
231+
- name: Uninstall MDE
232+
hosts: myhosts
233+
tasks:
234+
- name: Uninstall MDE
235+
ansible.builtin.script: "{{ mde_installer_script }} --remove"
236+
register: script_output
237+
args:
238+
executable: sudo
239+
240+
241+
- name: Display the installation output
242+
debug:
243+
msg: "Return code [{{ script_output.rc }}] {{ script_output.stdout }}"
244+
245+
- name: Display any installation errors
246+
debug:
247+
msg: "{{ script_output.stderr }}"
248+
249+
```
250+
251+
Run the below command to uninstall MDE using the above playbook
252+
253+
```bash
254+
ansible-playbook -i  /etc/ansible/hosts /etc/ansible/playbooks/uninstall_mdatp.yml --extra-vars "mde_installer_script=<path to mde_installer.sh>"
255+
```
256+
257+
## Deploy MDE using Ansible by configuring repositories manually
258+
259+
Follow the steps below after [downloading the onboarding package]() and completing [pre-requisites]() to deploy MDE by manually configuring the repositories for each Linux distribution
260+
261+
### Create Ansible YAML files
122262
123263
- Add the Defender for Endpoint repository and key, `add_apt_repo.yml`:
124264
125-
Defender for Endpoint on Linux can be deployed from one of the following channels:
126-
- *insiders-fast*, denoted as `[channel]`
127-
- *insiders-slow*, denoted as `[channel]`
128-
- *prod*, denoted as `[channel]` using the version name (see [Linux Software Repository for Microsoft Products](/linux/packages))
265+
- Defender for Endpoint on Linux can be deployed from one of the following channels:
266+
- *insiders-fast*, denoted as `[channel]`
267+
- *insiders-slow*, denoted as `[channel]`
268+
- *prod*, denoted as `[channel]` using the version name (see [Linux Software Repository for Microsoft Products](/linux/packages))
129269
130270
Each channel corresponds to a Linux software repository.
131271
@@ -134,17 +274,17 @@ Create a subtask or role files that contribute to a playbook or task.
134274
135275
In order to preview new features and provide early feedback, it's recommended that you configure some devices in your enterprise to use either *insiders-fast* or *insiders-slow*.
136276
137-
> [!WARNING]
277+
> [!WARNING]
138278
> Switching the channel after the initial installation requires the product to be reinstalled. To switch the product channel: uninstall the existing package, re-configure your device to use the new channel, and follow the steps in this document to install the package from the new location.
139279
140-
Note your distribution and version and identify the closest entry for it under `https://packages.microsoft.com/config/[distro]/`.
280+
Note your distribution and version and identify the closest entry for it under `https://packages.microsoft.com/config/[distro]/`.
141281
142-
In the following commands, replace *[distro]* and *[version]* with the information you've identified.
282+
In the following commands, replace *[distro]* and *[version]* with the information you've identified.
143283
144-
> [!NOTE]
284+
> [!NOTE]
145285
> In case of Oracle Linux and Amazon Linux 2, replace *[distro]* with "rhel". For Amazon Linux 2, replace *[version]* with "7". For Oracle Linux, replace *[version]* with the version of Oracle Linux.
146286
147-
```bash
287+
```bash
148288
- name: Add Microsoft APT key
149289
apt_key:
150290
url: https://packages.microsoft.com/keys/microsoft.asc

0 commit comments

Comments
 (0)