├── .gitignore ├── requirements.txt ├── vars ├── .gitignore ├── custom.yml.example └── droplets.yml ├── host_vars └── localhost ├── hosts └── local ├── provision.yml ├── tasks └── create_droplet.yml ├── LICENSE ├── README.md └── printnames.go /.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | dnsimple 2 | dopy 3 | ansible 4 | -------------------------------------------------------------------------------- /vars/.gitignore: -------------------------------------------------------------------------------- 1 | custom.yml 2 | !custom.yml.example 3 | -------------------------------------------------------------------------------- /vars/custom.yml.example: -------------------------------------------------------------------------------- 1 | --- 2 | default_key: xxxxx 3 | -------------------------------------------------------------------------------- /host_vars/localhost: -------------------------------------------------------------------------------- 1 | --- 2 | default_region: 2 3 | default_size: 63 4 | default_image: 4218810 5 | -------------------------------------------------------------------------------- /vars/droplets.yml: -------------------------------------------------------------------------------- 1 | --- 2 | droplets: 3 | - name: boringtorvalds 4 | - name: elegantpoincare 5 | -------------------------------------------------------------------------------- /hosts/local: -------------------------------------------------------------------------------- 1 | [local] 2 | localhost ansible_connection=local ansible_python_interpreter=/opt/boxen/homebrew/bin/python 3 | -------------------------------------------------------------------------------- /provision.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | gather_facts: False 4 | vars_files: 5 | - vars/custom.yml 6 | - vars/droplets.yml 7 | tasks: 8 | - include: tasks/create_droplet.yml droplets={{droplets}} 9 | -------------------------------------------------------------------------------- /tasks/create_droplet.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - digital_ocean: > 3 | state=present 4 | ssh_key_ids={{ default_key }} 5 | command=droplet 6 | name={{ item.name }}.local 7 | size_id={{ item.size|default(default_size) }} 8 | region_id={{ item.region|default(default_region) }} 9 | image_id={{ item.image|default(default_image) }} 10 | wait_timeout=500 11 | unique_name=true 12 | register: instances 13 | with_items: droplets 14 | - debug: var=instances.results 15 | - dnsimple: > 16 | state=present 17 | domain=secure-pipeline.com 18 | record={{ item.item.name }} 19 | type=A 20 | ttl=3600 21 | value={{ item.droplet.ip_address }} 22 | with_items: instances.results 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | Copyright (c) 2014 Gareth Rushgrove 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 18 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 19 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE 20 | OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This repository contains an [Ansible](http://www.ansible.com/) playbook 2 | to create machines in [Digital Ocean](https://www.digitalocean.com/) and 3 | add entries for each to DNS using the [DNSimple](http://dnsimple.com) API. 4 | 5 | ## Installation 6 | 7 | This project has a few python dependencies. 8 | 9 | ```bash 10 | pip install -r requirements.txt 11 | ``` 12 | 13 | ## Usage 14 | 15 | Note that this assumes you have a DigitalOcean and DNSimple account and 16 | have the relevant values stored in the following environment variable: 17 | `DO_CLIENT_ID`, `DO_API_KEY`, `DNSIMPLE_EMAIL` and `DNSIMPLE_API_TOKEN`. 18 | 19 | ```bash 20 | ansible-playbook -i hosts provision.yml 21 | ``` 22 | 23 | The specific code here has a few hardcoded elements that you'll likely 24 | want to change for your own usage. 25 | 26 | ## Generating configuration 27 | 28 | A small script is provided to generate random names for use in 29 | provisioning machines. The names are used as both the name of the 30 | instance and as the subdomain so need a good degree of uniqueness. 31 | 32 | ```bash 33 | go run printnames.go 34 | ``` 35 | 36 | This will print a YAML formatted configuration file for use by ansible. 37 | You'll probably run something like: 38 | 39 | ```bash 40 | go run printnames.go 200 > vars/droplets.yml 41 | ``` 42 | 43 | -------------------------------------------------------------------------------- /printnames.go: -------------------------------------------------------------------------------- 1 | // A modified version of the original, which is available in the docker source code at 2 | // https://github.com/dotcloud/docker/blob/master/pkg/namesgenerator/names-generator.go 3 | // Reused here under the terms of the Apache License 4 | 5 | package main 6 | 7 | import ( 8 | "log" 9 | "os" 10 | "strconv" 11 | "fmt" 12 | "math/rand" 13 | "time" 14 | ) 15 | 16 | var ( 17 | left = [...]string{"happy", "jolly", "dreamy", "sad", "angry", "pensive", "focused", "sleepy", "grave", "distracted", "determined", "stoic", "stupefied", "sharp", "agitated", "cocky", "tender", "goofy", "furious", "desperate", "hopeful", "compassionate", "silly", "lonely", "condescending", "naughty", "kickass", "drunk", "boring", "nostalgic", "ecstatic", "insane", "cranky", "mad", "jovial", "sick", "hungry", "thirsty", "elegant", "backstabbing", "clever", "trusting", "loving", "suspicious", "berserk", "high", "romantic", "prickly", "evil"} 18 | // Ada Lovelace invented the first algorithm. http://en.wikipedia.org/wiki/Ada_Lovelace (thanks James Turnbull) 19 | // Ada Yonath - an Israeli crystallographer, the first woman from the Middle East to win a Nobel prize in the sciences. http://en.wikipedia.org/wiki/Ada_Yonath 20 | // Adele Goldstine, born Adele Katz, wrote the complete technical description for the first electronic digital computer, ENIAC. http://en.wikipedia.org/wiki/Adele_Goldstine 21 | // Alan Turing was a founding father of computer science. http://en.wikipedia.org/wiki/Alan_Turing. 22 | // Albert Einstein invented the general theory of relativity. http://en.wikipedia.org/wiki/Albert_Einstein 23 | // Ambroise Pare invented modern surgery. http://en.wikipedia.org/wiki/Ambroise_Par%C3%A9 24 | // Archimedes was a physicist, engineer and mathematician who invented too many things to list them here. http://en.wikipedia.org/wiki/Archimedes 25 | // Barbara McClintock - a distinguished American cytogeneticist, 1983 Nobel Laureate in Physiology or Medicine for discovering transposons. http://en.wikipedia.org/wiki/Barbara_McClintock 26 | // Benjamin Franklin is famous for his experiments in electricity and the invention of the lightning rod. 27 | // Charles Babbage invented the concept of a programmable computer. http://en.wikipedia.org/wiki/Charles_Babbage. 28 | // Charles Darwin established the principles of natural evolution. http://en.wikipedia.org/wiki/Charles_Darwin. 29 | // Dennis Ritchie and Ken Thompson created UNIX and the C programming language. http://en.wikipedia.org/wiki/Dennis_Ritchie http://en.wikipedia.org/wiki/Ken_Thompson 30 | // Douglas Engelbart gave the mother of all demos: http://en.wikipedia.org/wiki/Douglas_Engelbart 31 | // Elizabeth Blackwell - American doctor and first American woman to receive a medical degree - http://en.wikipedia.org/wiki/Elizabeth_Blackwell 32 | // Emmett Brown invented time travel. http://en.wikipedia.org/wiki/Emmett_Brown (thanks Brian Goff) 33 | // Enrico Fermi invented the first nuclear reactor. http://en.wikipedia.org/wiki/Enrico_Fermi. 34 | // Erna Schneider Hoover revolutionized modern communication by inventing a computerized telephon switching method. http://en.wikipedia.org/wiki/Erna_Schneider_Hoover 35 | // Euclid invented geometry. http://en.wikipedia.org/wiki/Euclid 36 | // Françoise Barré-Sinoussi - French virologist and Nobel Prize Laureate in Physiology or Medicine; her work was fundamental in identifying HIV as the cause of AIDS. http://en.wikipedia.org/wiki/Fran%C3%A7oise_Barr%C3%A9-Sinoussi 37 | // Galileo was a founding father of modern astronomy, and faced politics and obscurantism to establish scientific truth. http://en.wikipedia.org/wiki/Galileo_Galilei 38 | // Gertrude Elion - American biochemist, pharmacologist and the 1988 recipient of the Nobel Prize in Medicine - http://en.wikipedia.org/wiki/Gertrude_Elion 39 | // Grace Hopper developed the first compiler for a computer programming language and is credited with popularizing the term "debugging" for fixing computer glitches. http://en.wikipedia.org/wiki/Grace_Hopper 40 | // Henry Poincare made fundamental contributions in several fields of mathematics. http://en.wikipedia.org/wiki/Henri_Poincar%C3%A9 41 | // Hypatia - Greek Alexandrine Neoplatonist philosopher in Egypt who was one of the earliest mothers of mathematics - http://en.wikipedia.org/wiki/Hypatia 42 | // Isaac Newton invented classic mechanics and modern optics. http://en.wikipedia.org/wiki/Isaac_Newton 43 | // Jane Colden - American botanist widely considered the first female American botanist - http://en.wikipedia.org/wiki/Jane_Colden 44 | // Jane Goodall - British primatologist, ethologist, and anthropologist who is considered to be the world's foremost expert on chimpanzees - http://en.wikipedia.org/wiki/Jane_Goodall 45 | // Jean Bartik, born Betty Jean Jennings, was one of the original programmers for the ENIAC computer. http://en.wikipedia.org/wiki/Jean_Bartik 46 | // Jean E. Sammet developed FORMAC, the first widely used computer language for symbolic manipulation of mathematical formulas. http://en.wikipedia.org/wiki/Jean_E._Sammet 47 | // Johanna Mestorf - German prehistoric archaeologist and first female museum director in Germany - http://en.wikipedia.org/wiki/Johanna_Mestorf 48 | // John McCarthy invented LISP: http://en.wikipedia.org/wiki/John_McCarthy_(computer_scientist) 49 | // June Almeida - Scottish virologist who took the first pictures of the rubella virus - http://en.wikipedia.org/wiki/June_Almeida 50 | // Karen Spärck Jones came up with the concept of inverse document frequency, which is used in most search engines today. http://en.wikipedia.org/wiki/Karen_Sp%C3%A4rck_Jones 51 | // Leonardo Da Vinci invented too many things to list here. http://en.wikipedia.org/wiki/Leonardo_da_Vinci. 52 | // Linus Torvalds invented Linux and Git. http://en.wikipedia.org/wiki/Linus_Torvalds 53 | // Lise Meitner - Austrian/Swedish physicist who was involved in the discovery of nuclear fission. The element meitnerium is named after her - http://en.wikipedia.org/wiki/Lise_Meitner 54 | // Louis Pasteur discovered vaccination, fermentation and pasteurization. http://en.wikipedia.org/wiki/Louis_Pasteur. 55 | // Malcolm McLean invented the modern shipping container: http://en.wikipedia.org/wiki/Malcom_McLean 56 | // Maria Ardinghelli - Italian translator, mathematician and physicist - http://en.wikipedia.org/wiki/Maria_Ardinghelli 57 | // Maria Kirch - German astronomer and first woman to discover a comet - http://en.wikipedia.org/wiki/Maria_Margarethe_Kirch 58 | // Maria Mayer - American theoretical physicist and Nobel laureate in Physics for proposing the nuclear shell model of the atomic nucleus - http://en.wikipedia.org/wiki/Maria_Mayer 59 | // Marie Curie discovered radioactivity. http://en.wikipedia.org/wiki/Marie_Curie. 60 | // Marie-Jeanne de Lalande - French astronomer, mathematician and cataloguer of stars - http://en.wikipedia.org/wiki/Marie-Jeanne_de_Lalande 61 | // Mary Leakey - British paleoanthropologist who discovered the first fossilized Proconsul skull - http://en.wikipedia.org/wiki/Mary_Leakey 62 | // Muhammad ibn Jābir al-Ḥarrānī al-Battānī was a founding father of astronomy. http://en.wikipedia.org/wiki/Mu%E1%B8%A5ammad_ibn_J%C4%81bir_al-%E1%B8%A4arr%C4%81n%C4%AB_al-Batt%C4%81n%C4%AB 63 | // Niels Bohr is the father of quantum theory. http://en.wikipedia.org/wiki/Niels_Bohr. 64 | // Nikola Tesla invented the AC electric system and every gaget ever used by a James Bond villain. http://en.wikipedia.org/wiki/Nikola_Tesla 65 | // Pierre de Fermat pioneered several aspects of modern mathematics. http://en.wikipedia.org/wiki/Pierre_de_Fermat 66 | // Rachel Carson - American marine biologist and conservationist, her book Silent Spring and other writings are credited with advancing the global environmental movement. http://en.wikipedia.org/wiki/Rachel_Carson 67 | // Radia Perlman is a software designer and network engineer and most famous for her invention of the spanning-tree protocol (STP). http://en.wikipedia.org/wiki/Radia_Perlman 68 | // Richard Feynman was a key contributor to quantum mechanics and particle physics. http://en.wikipedia.org/wiki/Richard_Feynman 69 | // Rob Pike was a key contributor to Unix, Plan 9, the X graphic system, utf-8, and the Go programming language. http://en.wikipedia.org/wiki/Rob_Pike 70 | // Rosalind Franklin - British biophysicist and X-ray crystallographer whose research was critical to the understanding of DNA - http://en.wikipedia.org/wiki/Rosalind_Franklin 71 | // Sophie Kowalevski - Russian mathematician responsible for important original contributions to analysis, differential equations and mechanics - http://en.wikipedia.org/wiki/Sofia_Kovalevskaya 72 | // Sophie Wilson designed the first Acorn Micro-Computer and the instruction set for ARM processors. http://en.wikipedia.org/wiki/Sophie_Wilson 73 | // Stephen Hawking pioneered the field of cosmology by combining general relativity and quantum mechanics. http://en.wikipedia.org/wiki/Stephen_Hawking 74 | // Steve Wozniak invented the Apple I and Apple II. http://en.wikipedia.org/wiki/Steve_Wozniak 75 | // Werner Heisenberg was a founding father of quantum mechanics. http://en.wikipedia.org/wiki/Werner_Heisenberg 76 | // William Shockley, Walter Houser Brattain and John Bardeen co-invented the transistor (thanks Brian Goff). 77 | // http://en.wikipedia.org/wiki/John_Bardeen 78 | // http://en.wikipedia.org/wiki/Walter_Houser_Brattain 79 | // http://en.wikipedia.org/wiki/William_Shockley 80 | right = [...]string{"lovelace", "franklin", "tesla", "einstein", "bohr", "davinci", "pasteur", "nobel", "curie", "darwin", "turing", "ritchie", "torvalds", "pike", "thompson", "wozniak", "galileo", "euclid", "newton", "fermat", "archimedes", "poincare", "heisenberg", "feynman", "hawking", "fermi", "pare", "mccarthy", "engelbart", "babbage", "albattani", "ptolemy", "bell", "wright", "lumiere", "morse", "mclean", "brown", "bardeen", "brattain", "shockley", "goldstine", "hoover", "hopper", "bartik", "sammet", "jones", "perlman", "wilson", "kowalevski", "hypatia", "goodall", "mayer", "elion", "blackwell", "lalande", "kirch", "ardinghelli", "colden", "almeida", "leakey", "meitner", "mestorf", "rosalind", "sinoussi", "carson", "mcclintock", "yonath"} 81 | ) 82 | 83 | func GetRandomName() string { 84 | rand.Seed(time.Now().UnixNano()) 85 | name := fmt.Sprintf("%s%s", left[rand.Intn(len(left))], right[rand.Intn(len(right))]) 86 | return name 87 | } 88 | 89 | func PrintYamlHeader() { 90 | fmt.Println("---") 91 | fmt.Println("droplets:") 92 | } 93 | 94 | func PrintName() { 95 | fmt.Println("- name:", GetRandomName()) 96 | } 97 | 98 | func main() { 99 | if len(os.Args) != 2 { 100 | log.Fatal("Must specify number of names required as only argument") 101 | } 102 | required_names, err := strconv.Atoi(os.Args[1]) 103 | if err != nil { 104 | log.Fatal("Number of names argument must be an integer") 105 | } 106 | PrintYamlHeader() 107 | count := 1 108 | for count < required_names+1 { 109 | count += 1 110 | PrintName() 111 | } 112 | } 113 | --------------------------------------------------------------------------------