Last active
August 28, 2016 16:37
-
-
Save arubdesu/5ba271d783efc04339d2 to your computer and use it in GitHub Desktop.
workflow step in DeployStudio to stop setting up for binding with hostname in a 'bad' (read= already used on a pc or some other mistakenly chosen) AD OU/container
This file contains hidden or 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
| #!/usr/bin/python | |
| """Checks if a computername already exists in a container we can't write to, | |
| to prevent errors binding.""" | |
| import os | |
| import subprocess | |
| import sys | |
| def main(): | |
| """gimme some main""" | |
| read_only_user = "ouruser" | |
| password = "super_sekrit!!" | |
| domain = "domain.com" | |
| ds_repo_path = os.environ.get('DS_REPOSITORY_PATH') | |
| ldapsearch = ds_repo_path + "/Backups/admin/ldapsearch" | |
| ds_hostname = os.environ.get('DS_HOSTNAME') | |
| cmd = [ldapsearch, "-LLL", "-h", domain, "-x", "-D", read_only_user + '@' + domain, "-w", password, "-b", "DC=domain,DC=com", "name=" + ds_hostname] | |
| output = subprocess.check_output(cmd) | |
| if len(output) > 234: | |
| listed = output.strip('\n') | |
| if not "OU=writable,OU=container,DC=domain,DC=com" in listed: | |
| print "baaaad" | |
| sys.exit(1) | |
| else: | |
| print "in our Macs/Devices group" | |
| else: | |
| print "unused name, clear to proceed" | |
| sys.exit(0) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment