Skip to main content

NinjaRMM Deployment - [MAC]

Summary

This script deploys the NinjaRMMAgent to MAC OS, based on the article provided below: Agent Installation Tokenization. It depends on the Authorization token, which will be kept in the company or site custom fields.

Sample Run

Sample Run 1

Sample Run 2

Dependencies

CW RMM - Ninja Migration Custom fields

Group - Ninja RMM Deployment

Solution - CW RMM to Ninja Migration

Task Creation

Script Details

Step 1

Navigate to AutomationTasks
step1

Step 2

Create a new Script Editor style task by choosing the Script Editor option from the Add dropdown menu
step2

The New Script page will appear on clicking the Script Editor button:
step3

Step 3

Name: NinjaRMM Deployment - [MAC]
Description: This script deploys the NinjaRMMAgent to MAC OS, based on the article provided below: https://ninjarmm.zendesk.com/hc/en-us/articles/27524794230669-NinjaOne-Agent-Installation-Agent-Tokenization. It depends on the Authorization token, which will be kept in the company or site custom fields.
Category: Application

Detail

Script Editor

Click the Add Row button in the Script Editor section to start creating the script
AddRow

A blank function will appear:
BlankFunction

Note: Limit all the function to MacOs machines.

MacOs

Row 1 Function: Pre-defined Variable

Select the Pre-defined Variable and provide the details and click on Save.

Variable: Deployment

Custom Field: Ninja Deployment Enable

Set Pre-defined 1

After clicking on Save the Pre-defined will show data as:

Deployment

Row 2 Function: Pre-defined Variable

Select the Pre-defined Variable and provide the details and click on Save. Make sure to select the Ninja Deployment Exclude site level custom field.

Variable: DeploymentExL

Custom Field: Ninja Deployment Exclude

Set Pre-defined 2

After clicking on Save the Pre-defined will show data as:

Deployment ExL

Row 3 Function: Pre-defined Variable

Select the Pre-defined Variable and provide the details and click on Save. Make sure to select the Ninja Deployment Exclude endpoint level custom field.

Variable: DeploymentExC

Custom Field: Ninja Deployment Exclude

Set Pre-defined 3

After clicking on Save the Pre-defined will show data as:

Deployment ExC

Row 4 Function: Pre-defined Variable

Select the Pre-defined Variable and provide the details and click on Save.

Variable: OrgID

Custom Field: Ninja_Org_ID

Set Pre-defined 4

After clicking on Save the Pre-defined will show data as:

Org ID

Row 5 Function: Pre-defined Variable

Select the Pre-defined Variable and provide the details and click on Save.

Variable: LocID

Custom Field: Ninja_Site_ID

Set Pre-defined 5

After clicking on Save the Pre-defined will show data as:

Loc ID

Row 6 Logic: If/Then/Else

Add a logic If/Else/Then by clicking the Add Logic button:

If/Else/Then

Row 6a Condition: Custom Field Contains

In the IF part, enter - in the right box for the Custom Field "Ninja_Org_ID" contains part.

Row 6A

Row 6b Function: Bash Script

Add another row and select the Bash Script function.

Bash

The following function will pop up on the screen:

Bash Script 2

Paste in the following Bash script and leave the expected time of script execution to 900 seconds. Click the Save button.

sudo curl https://app.ninjarmm.com/ws/api/v2/generic-installer/NinjaOneAgent-x64.pkg -L --output /tmp/NinjaOneAgent-x64.pkg && sudo sh -c 'echo "@OrgID@" > /tmp/.~' && sudo installer -pkg /tmp/NinjaOneAgent-x64.pkg -target / && echo "Installation successful." || { echo "Failed to install Ninja RMM agent."; exit 1; }

Bash Script

Limit the bash file to run on Mac machines only.

Limit

Row 6c Logic: If/Then

Logic If/Then

Logic Selected

Row 6c(i) Condition: Output Contains

In the IF part, enter Failed to install Ninja in the right box of the "Output Contains" part.

Condition

Row 6c(ii) Function: Set Custom Field

Add a new row by clicking the Add Row button.

Add Row 1

Search and select the Set Custom Field function.

Select Custom Field

Search and select Ninja Deployment Result in the Search Custom Field field, set Failed in the Value field, and click the Save button.

Set Custom field 2

Custom field 3

Row 6c(iii) Function: Script Exit

Add a new row in the IF part by clicking on the Add row button.

Add Row 3

In the script exit message, simply type The Ninja Deployment failed on the Mac Agent. Refer to the logs: %output%

Script Exit Message

Row 6d Function: Script Log

Add a new row by clicking the Add Row button.

Add Row 5

Search and select the Script Log function.

Script Log

The following function will pop up on the screen:

Script Log Empty

In the script log message, simply type %Output% and click the Save button.

Script Log Message

Row 6e Function: Set Custom Field

Add a new row by clicking the Add Row button after END IF.

Add Row 7

Search and select the Set Custom Field function.

Select Custom Field

Search and select Ninja Deployment Result in the Search Custom Field field, set Success in the Value field, and click the Save button.

Set custom field value

Success

Row 6f Function: Script Exit

Add a new row by clicking on the Add row button.

6f Image

In the script exit message, leave blank

Exit Message

Row 6g - Else Section

Row 6g Logic: If/Then

Add a logic If/Then by clicking the Add Logic button:

Logic If/Then

Logic Selected

Row 6g (i) Condition: Custom Field Contains

In the IF part, enter - in the right box for the Custom Field "Ninja_Site_ID" contains part.

Site ID

Row 6g (ii) Function: Bash Script

Add another row and select the Bash Script function.

Bash Script

The following function will pop up on the screen:

Bash Script 2

Paste in the following Bash script and leave the expected time of script execution to 900 seconds. Click the Save button.

sudo curl https://app.ninjarmm.com/ws/api/v2/generic-installer/NinjaOneAgent-x64.pkg -L --output /tmp/NinjaOneAgent-x64.pkg && sudo sh -c 'echo "@LocID@" > /tmp/.~' && sudo installer -pkg /tmp/NinjaOneAgent-x64.pkg -target / && echo "Installation successful." || { echo "Failed to install Ninja RMM agent."; exit 1; }

Bash cmd

Limit the bash file to run on Mac machines only.

LimitMac

Row 6h Logic: If/Then

Add a logic If/Then by clicking the Add Logic button

Logic If/Then

Logic Selected

Row 6h(i) Condition: Output Contains

In the IF part, enter Failed to install Ninja in the right box of the "Output Contains" part.

Condition

Row 6h(ii) Function: Set Custom Field

Add a new row by clicking the Add Row button.

Add Row 1

Search and select the Set Custom Field function.

Select Custom Field

Search and select Ninja Deployment Result in the Search Custom Field field, set Failed in the Value field, and click the Save button.

Set Custom field 2

Failed Value

Row 6h(iii) Function: Script Exit

Add a new row by clicking on the Add row button.

Add Row 5

In the script exit message, simply type The Ninja Deployment failed on the Mac Agent. Refer to the logs: %output%

Exit Msg

Row 6i Function: Script Log

After END IF add a new row by clicking the Add Row button.

Add Row 5

Search and select the Script Log function.

Script Log Function

The following function will pop up on the screen:

Script Log Empty

In the script log message, simply type %Output% and click the Save button.

Script Log Message

Row 6j Function: Set Custom Field

Add a new row by clicking the Add Row button.

Add Row 7

Search and select the Set Custom Field function.

Select Custom Field

Search and select Ninja Deployment Result in the Search Custom Field field, set Success in the Value field, and click the Save button.

Set custom field value

Success CF

Row 6k Function: Script Exit

Add a new row by clicking on the Add row button.

Script Exit

In the script exit message, leave blank

Blank

Row 7 Function: Script Exit

Add a new row by clicking on the Add row after END IF button.

Row 8

In the script exit message write, The Ninja_Org_ID and Ninja_Site_ID both are empty. The script needs the authorization token for its working.

Script Exit Msg

Save Task

Click the Save button at the top-right corner of the screen to save the script.
SaveButton

Completed Task

Complete Task 1 Complete Task 2 Complete Task 3

Deployment

This task is required to be deployed using a dynamic group.

It can be scheduled to run every 1 hour. Follow the below deployment step to schedule it.

  • Go to Automation > Tasks.

  • Search for NinjaRMM Deployment - [MAC]

  • Then click on Schedule

Schedule Task

  • Select the Target group

Target Set

  • Click Device Group -> Search for Ninja -> Select Ninja RMM Deployment group and click save selection

Target select

  • Click on Schedule option, and set the time and click on Repeat to set it to run every hour

Repeat

Schedule Task

Output

  • Custom field
  • Script Log