Created
June 6, 2016 00:28
-
-
Save markryd/b790c184f3938d68393187dddd71a130 to your computer and use it in GitHub Desktop.
Register multiple Octopus SSH Targets for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo installing mono | |
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF | |
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list | |
sudo apt-get update | |
sudo apt-get install -y mono-complete | |
function createMachine() { | |
username=t-$RANDOM | |
password=p-$RANDOM | |
echo adding user $username | |
sudo useradd -m $username | |
echo "$username:$password" | sudo chpasswd | |
sudo /etc/init.d/ssh reload | |
machineName=$(echo Ssh Machine $username) | |
environmentId=$(wget --header="X-Octopus-ApiKey: $apiKey" -O- ${serverUrl}/api/environments | jq ".Items[] | select(.Name==\"${environment}\") | .Id" -r) | |
accountId=$(wget --header="X-Octopus-ApiKey: $apiKey" --post-data "{\"AccountType\":\"UsernamePassword\",\"EnvironmentIds\": [],\"Username\":\"$username\",\"Password\":{\"NewValue\":\"$password\"},\"Name\":\"TentacleAcccount $username\",\"Description\":\"Ssh Machine\"}" -O- ${serverUrl}/api/accounts | jq ".Id" -r) | |
echo account $accountId added | |
machineId=$(wget --header="X-Octopus-ApiKey: $apiKey" --post-data "{\"Endpoint\":{\"CommunicationStyle\":\"Ssh\",\"AccountId\":\"$accountId\",\"Host\":\"$localip\",\"Port\":\"22\",\"Fingerprint\":\"$fingerprint\"},\"EnvironmentIds\":[\"$environmentId\"],\"Name\":\"$machineName\",\"Roles\":[\"linux\"]}" -O- ${serverUrl}/api/machines | jq ".Id" -r) | |
echo Added machine \"$machineName\" '('$machineId') - Launching health check task' | |
wget --header="X-Octopus-ApiKey: $apiKey" --post-data "{\"Name\":\"Health\",\"Description\":\"Check $machineName health\",\"Arguments\":{\"Timeout\":\"00:05:00\",\"MachineIds\":[\"$machineId\"]}}" -O- ${serverUrl}/api/tasks | jq ".Id" -r | |
} | |
echo setting up machine | |
sudo apt-get install -y jq | |
apiKey=$(wget -qO- ${serverApiKeyUrl} | strings -n 8) | |
localip=$(ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{ print $1}') | |
fingerprint=$(ssh-keygen -lf /etc/ssh/ssh_host_rsa_key.pub | cut -d' ' -f2 | awk '{ print $1}') | |
sudo sed -i.bak -e s/'PasswordAuthentication no'/'PasswordAuthentication yes'/g /etc/ssh/sshd_config | |
for (( c=1; c<=${numberOfUsers}; c++ )) | |
do | |
createMachine | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment