Skip to content

Instantly share code, notes, and snippets.

@peasead
Last active March 29, 2023 03:10
Show Gist options
  • Save peasead/33394868ddbd773c39bedde4011b4f6a to your computer and use it in GitHub Desktop.
Save peasead/33394868ddbd773c39bedde4011b4f6a to your computer and use it in GitHub Desktop.
Install the Elastic Agent on macOS systems.
#!/bin/bash -eux
# Single script to install the Elastic Agent on macOS
# Downloads the Elastic Agent and saves it to your computer in the current directory (example in Downloads, Desktop, etc.)
curl -OL https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.2.0-darwin-x86_64.tar.gz
# Uses the Tar command to decompress the Elastic Agent and prepare it for installation
tar zxf elastic-agent-8.2.0-darwin-x86_64.tar.gz
# Enters the Elastic Agent directory that was decompressed in the previous step
cd elastic-agent-8.2.0-darwin-x86_64
# Uses "super user do" to install the Elastic Agent, sends data to Elastic Cloud, and enrolls it in Fleet so that updates to the Agent can be managed within Kibana
sudo ./elastic-agent install -f --kibana-url=fleet-server-address --enrollment-token=enrollment-token
@jbeas408
Copy link

jbeas408 commented May 19, 2022

Hi @peasead did this ever work for you? I used this script but updated the version # and it seems to download/extract the tar.gz file but that's about it. I don't believe it is doing the cd or after that step. Also I noticed If I push this from Jamf and not force the policy sync (sudo Jamf policy) it never installs but errors out (first screenshot). If I force the policy I get the second error.

Screen Shot 2022-05-19 at 8 02 21 AM

Force sync policy log

Screen Shot 2022-05-19 at 8 09 40 AM
Screen Shot 2022-05-19 at 8 09 58 AM
Screen Shot 2022-05-19 at 8 10 22 AM

@peasead
Copy link
Author

peasead commented May 19, 2022

Hey @jbeas408

I can't speak to the Jamf portion, but a bit of *NIX-like systems info (sorry if you know this) - when you run a shell script, you're running in a sub-shell. So, if you took the script above and added a pwd at the end, you'd see the shell script is in the right directory.

#!/bin/bash -eux
curl -OL https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-8.2.0-darwin-x86_64.tar.gz
tar zxf elastic-agent-8.2.0-darwin-x86_64.tar.gz
cd elastic-agent-8.2.0-darwin-x86_64
pwd

$ sh script.sh
/path/to/elastic-agent-8.2.0-darwin-x86_64 <- this is the pwd output and you can see, we're in the right directory

Once the script stops, the sub-shell is exited and you're back to your normal directory.

Another way to accomplish this would be by running . script.sh, which leverages the source architecture and will have more of a result like you're probably expecting.

Again, I'm not entirely sure how Jamf does things, but that's how you'd do it natively on the command-line.

@yassermkh
Copy link

If I deploy the script natively on Terminal it works but it asks :
Elastic Agent will be installed at /Library/Elastic/Agent and will run as a service. Do you want to continue? [Y/n]
so when I deploy it using Jamf it shows nothing thus it does nothing !
@jbeas408 did you manage to fix it?

@peasead
Copy link
Author

peasead commented Oct 27, 2022

@yassermkh did you use the -f flag? That should do a force installation.

$ elastic-agent install --help

Usage:
  elastic-agent install [flags]
...
-f, --force  Force overwrite the current and do not prompt for confirmation
...

@yassermkh
Copy link

no didn't use that argument but I managed to make it work by answering that message with Y using :

yes | ./elastic-agent install -f --kibana-url=fleet-server-address --enrollment-token=enrollment-token

@yassermkh
Copy link

Anyone managed to grey out the elastic-agent in the login items in Ventura!?

@peasead
Copy link
Author

peasead commented Jan 24, 2023

Hey @yassermkh you might get better support on the Elastic Agent Discuss site. https://discuss.elastic.co/tags/c/elastic-stack/beats/28/elastic-agent

@charlesfair
Copy link

"Elastic Agent provides commands for running Elastic Agent, managing Fleet Server, and doing common tasks."
https://www.elastic.co/guide/en/fleet/current/elastic-agent-cmd-options.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment