Posted on 05-11-2019 12:11 PM
Hey, I am looking ideas to use Python to accomplish various tasks with Jamf. I am not sure where to get started or how powerful Python is with Jamf Pro.
Solved! Go to Solution.
Posted on 05-13-2019 07:26 PM
This list is slightly out of date, but is a still a very good list of Mac/Apple admin tools built with Python. https://github.com/timsutton/python-macadmin-tools
Some of the best known are Munki, AutoPkg, dockutil, and outset. There are a ton of others.
Python also gives you access to PyObjC which extends your scripting possibilities even further if you're interested in experimenting with Apple frameworks. Something like this - https://github.com/gregneagle/macaduk2017
Bash is still great and useful in many situations. You'll notice though that most open source Apple management projects aren't written in it. Instead they prefer Python, Ruby, Swift, etc. Guess I can't provide a definitive answer as to why, but in my opinion it's because those languages handle data processing much better than bash and have built in functions/modules for common tasks. Things like text manipulation, reading/writing JSON, looping over lists, etc. are just way easier.
Think ultimately it's good to use the tool that works for your situation. If bash is that tool then go for it.
Posted on 05-13-2019 01:09 AM
Hey,
how powerful Python is with Jamf Pro
I was wondering the same. I especially wonder if it's possible to import any modules into JAMF Python scripts as Python is way more powerful with modules.
If modules don't work I don't really see any reason to use Python instead of e.g. bash.
Posted on 05-13-2019 05:39 AM
I started digging into Python about a year ago and thus far anything I can do in BASH I can do in Python. In my limited experience modules work just fine depending on the module of course. I have a large clustered Linux environment so I wrote a tool in Python that allows me to run commands against all of the nodes in a loop. This helps with stopping, rebooting, or restarting Tomcat for upgrades etc. I would recommend picking a problem or project that you would normally solve with BASH and figure out how to do it in Python.
Posted on 05-13-2019 04:25 PM
We run a couple of python scripts:
1, Grabs the class information from a csv export of our SIS, grabs assest information from an Access database and device assignments from an SQL database (Disco). It then sets users room numbers, device assignments and device names in JAMF. Devices are named with the users full name and room number. Smart groups then creates classes or severely restricts devices assigned to anyone that has left.
2, We create a daily data dump of installed apps on each device by room number. This is written to a staff shared drive so they have instant access to last nights inventory.
Regards
Graeme
Posted on 05-13-2019 07:26 PM
This list is slightly out of date, but is a still a very good list of Mac/Apple admin tools built with Python. https://github.com/timsutton/python-macadmin-tools
Some of the best known are Munki, AutoPkg, dockutil, and outset. There are a ton of others.
Python also gives you access to PyObjC which extends your scripting possibilities even further if you're interested in experimenting with Apple frameworks. Something like this - https://github.com/gregneagle/macaduk2017
Bash is still great and useful in many situations. You'll notice though that most open source Apple management projects aren't written in it. Instead they prefer Python, Ruby, Swift, etc. Guess I can't provide a definitive answer as to why, but in my opinion it's because those languages handle data processing much better than bash and have built in functions/modules for common tasks. Things like text manipulation, reading/writing JSON, looping over lists, etc. are just way easier.
Think ultimately it's good to use the tool that works for your situation. If bash is that tool then go for it.
Posted on 05-13-2019 08:50 PM
Thanks @nstrauss much appreciated and is exactly what I was looking for.
Posted on 08-04-2021 02:46 PM
Hi @kdean
We are working on two tools, "python-jamf" and "jctl" and we will be presenting on them at JNUC 2021.
Presentation will be named "Turn 1000 Clicks into 1 with python-jamf and jctl"
`python-jamf` is a library for connecting to a Jamf Server that maps directly to the Jamf Pro Classic API. It is the basis for the `jctl` tool to automate patch management & packages and many other items. We are actively developing the tools and provides automation and performing tasks quickly on your Jamf Pro server.
Here are the GitHub repositories, if you are interested in checking them out...
python-jamf
https://github.com/univ-of-utah-marriott-library-apple/python-jamf
jctl
https://github.com/univ-of-utah-marriott-library-apple/jctl
We have a channel in MacAdmin's slack if you have any questions or need help with setup and usage:
jctl