Last active
November 30, 2016 12:54
-
-
Save Valian/f440d265b878edd7c4ffed55ac4a836f to your computer and use it in GitHub Desktop.
Simple script to find all server IPs from OVH panel site and print ready to use Docker Swarm inventory file
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
function get_ansible_config(managersCount, managersStartNr, workersStartNr) { | |
var createAnsibleString = function(name, startNumber){ | |
return function(a, i) { | |
return name + (i + 1 + (startNumber || 0)) + ' ansible_ssh_host=' + a + ' ansible_ssh_user=ubuntu'; | |
} | |
}; | |
var addresses = $x('//*[@data-ng-if="ip.ip"]/text()') | |
.filter(function(a){return a.wholeText.trim() != ""}) | |
.map(function(a) {return a.wholeText.trim()}); | |
var str = ""; | |
str += addresses.filter(function(_, i) {return i < managersCount}) | |
.map(createAnsibleString('manager', managersStartNr)) | |
.join('\n'); | |
str += '\n\n'; | |
str += addresses.filter(function(_, i) { return i >= managersCount}) | |
.map(createAnsibleString('worker', workersStartNr)) | |
.join('\n'); | |
return str | |
} | |
// Output | |
// manager1 ansible_ssh_host=10.10.10.10 ansible_ssh_user=ubuntu | |
// manager2 ansible_ssh_host=10.10.10.10 ansible_ssh_user=ubuntu | |
// worker1 ansible_ssh_host=10.10.10.12 ansible_ssh_user=ubuntu | |
// worker2 ansible_ssh_host=10.10.10.13 ansible_ssh_user=ubuntu |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment