Automate Site Creation

RDowson
New Contributor III

I have around 300 sites that I need to create. Is there a way that I can automate this?

5 REPLIES 5

Hugonaut
Valued Contributor II

I believe you can do this with The Mut! Basically create a spreadsheet with the site names and the site flag and upload it to your jamf server.

https://jssmut.weebly.com/

here is the github: https://github.com/mike-levenick/mut you can find some good examples here for what you need to do.

________________
Looking for a Jamf Managed Service Provider? Look no further than Rocketman
________________


Virtual MacAdmins Monthly Meetup - First Friday, Every Month

stevewood
Honored Contributor II
Honored Contributor II

I do not believe MUT will create sites. It will allow you to assign Macs to sites by ID or by name.

To do what you want, you'll probably need to us the API. You'll need a CSV file with just the site names in it, then the following should work:

#!/bin/sh
args=("$@")
jssAPIUsername='a-user-with-write-permissions'
jssAPIPassword='the-password'
jssAddress="https://your.jps.com"
file="${args[0]}"

#Verify we can read the file
data=`cat $file`
if [[ "$data" == "" ]]; then
    echo "Unable to read the file path specified"
    echo "Ensure there are no spaces and that the path is correct"
    exit 1
fi

file_length=`awk -F, 'END {printf "%s
", NR}' $file`
counter="0"

while [ $counter -lt $file_length ]
do
    counter=$[$counter+1]
    line=`echo "$data" | head -n $counter | tail -n 1`

    site_name=`echo "$line" | awk -F , '{print $1}'`

    xml="<site><name>${site_name}</name></site>"

    output=`curl -ku ${jssAPIUsername}:${jssAPIPassword} "$jssAddress/JSSResource/sites/id/0" -X POST -H "Content-Type: text/xml" -d "<?xml version="1.0" encoding="ISO-8859-1"?>$xml"`

done
exit 0

Test this with one or two sites in a file.

HTH

RDowson
New Contributor III

Thanks!

Where do I place the file and how do I point the script to it?

stevewood
Honored Contributor II
Honored Contributor II

@RDowson sorry, forgot that piece of info. ;-)

Save the script anywhere you want, maybe your home folder. Save the list to the same place. Then you would invoke the script like this:

~/createSites.sh <listfilename>

Make sense?

RDowson
New Contributor III

That makes sense, thanks.