├── .gitignore ├── LICENSE ├── README.md ├── Vagrantfile ├── ansible.cfg ├── galaxy-requirements.txt ├── playbooks ├── hellobaby.yml └── update_galaxy.yml └── roles ├── galaxy ├── Ansibles.apt │ ├── .gitignore │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── defaults │ │ └── main.yml │ ├── files │ │ └── etc_apt_sources.list │ ├── meta │ │ ├── .galaxy_install_info │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ ├── templates │ │ └── etc_apt_apt.conf.d_10general.j2 │ └── test.yml └── angstwad.docker_ubuntu │ ├── LICENSE │ ├── README.md │ ├── defaults │ └── main.yml │ ├── handlers │ └── main.yml │ ├── meta │ ├── .galaxy_install_info │ └── main.yml │ └── tasks │ └── main.yml └── image_building └── hellobaby_image ├── defaults └── main.yml ├── meta └── main.yml ├── tasks └── main.yml └── templates ├── Dockerfile └── runapp.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Victor Lin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ansible-docker-demo 2 | =================== 3 | 4 | A simple ansible project for demonstrating how to build a docker image. Read the article - [Building docker images with ansible](http://victorlin.me/posts/2014/08/11/building-docker-image-with-ansible) 5 | 6 | Run the demo 7 | ============ 8 | 9 | To run this demo, you need to install ansible and [vagrant](http://www.vagrantup.com) with vbguest plugin. Then 10 | 11 | ``` 12 | vagrant up 13 | ``` 14 | 15 | Then, let's build the image, here you run 16 | 17 | ``` 18 | ansible-playbook \ 19 | -i .vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory \ 20 | -u vagrant --private-key=~/.vagrant.d/insecure_private_key \ 21 | playbooks/hellobaby.yml 22 | ``` 23 | 24 | It will prompt you which version and interation number to build like this 25 | 26 | ``` 27 | hellobaby_version [1.0.0]: 28 | hellobaby_iteration [1]: 29 | ``` 30 | 31 | Just press enter twice to use the default value. Have a break, it should be done pretty soon. 32 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | VAGRANTFILE_API_VERSION = "2" 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | config.vm.box = "precise64" 8 | config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box" 9 | config.vbguest.auto_update = true 10 | config.vbguest.auto_reboot = true 11 | config.vm.provision "ansible" do |ansible| 12 | ansible.playbook = "playbooks/update_galaxy.yml" 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = roles/image_building:roles/galaxy 3 | -------------------------------------------------------------------------------- /galaxy-requirements.txt: -------------------------------------------------------------------------------- 1 | Ansibles.apt 2 | angstwad.docker_ubuntu -------------------------------------------------------------------------------- /playbooks/hellobaby.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Build Hello baby app image 3 | hosts: all 4 | sudo: yes 5 | vars_prompt: 6 | - name: hellobaby_version 7 | prompt: "hellobaby_version" 8 | default: "1.0.0" 9 | private: no 10 | - name: hellobaby_iteration 11 | prompt: "hellobaby_iteration" 12 | default: 1 13 | private: no 14 | roles: 15 | - Ansibles.apt 16 | - hellobaby_image 17 | -------------------------------------------------------------------------------- /playbooks/update_galaxy.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install dependency galaxy roles 3 | hosts: localhost 4 | connection: local 5 | sudo: no 6 | tasks: 7 | - name: Install dependency galaxy roles 8 | command: > 9 | ansible-galaxy install 10 | -r ../galaxy-requirements.txt 11 | -p ../roles/galaxy 12 | --force 13 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .AppleDouble 3 | .LSOverride 4 | Icon 5 | ._* 6 | .Spotlight-V100 7 | .Trashes 8 | .vagrant 9 | test 10 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | before_install: 5 | - sudo apt-get update -qq 6 | - sudo apt-get install -qq python-apt python-pycurl 7 | install: 8 | - pip install ansible==1.5.0 9 | script: 10 | - echo localhost > inventory 11 | - ansible-playbook --syntax-check -i inventory test.yml 12 | - ansible-playbook -i inventory test.yml --connection=local --sudo 13 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2014 Pieterjan Vandaele 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/README.md: -------------------------------------------------------------------------------- 1 | ## Ansibles - apt [![Build Status](https://travis-ci.org/Ansibles/apt.png)](https://travis-ci.org/Ansibles/apt) 2 | 3 | Ansible role which executes apt-get update to ensure the local APT package cache is up to date. At the same time, it cleans it from packages and .deb files which are no longer needed. 4 | 5 | 6 | #### Variables 7 | 8 | ```yaml 9 | apt_reset_source_list: no # reset the /etc/apt/sources.list to the default 10 | apt_cache_valid_time: 3600 # Time (in seconds) the apt cache stays valid 11 | apt_install_recommends: no # whether or not to install the "recommended" packages 12 | apt_install_suggests: no # whether or not to install the "suggested" packages 13 | apt_autoremove: yes # remove packages that are no longer needed for dependencies 14 | apt_autoclean: yes # remove .deb files for packages no longer on your system 15 | ``` 16 | 17 | Remark: Beware that setting `apt_install_recommends` and `apt_install_suggests` to `yes` may heavily increase the apt-requirements (and hence disk usage). You should proceed cautiously changing these. 18 | 19 | 20 | #### License 21 | 22 | Licensed under the MIT License. See the LICENSE file for details. 23 | 24 | 25 | #### Feedback, bug-reports, requests, ... 26 | 27 | Are [welcome](https://github.com/ansibles/apt/issues)! 28 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/defaults/main.yml: -------------------------------------------------------------------------------- 1 | # file: apt/defaults/main.yml 2 | 3 | apt_reset_source_list: no # reset the /etc/apt/sources.list to the default 4 | apt_cache_valid_time: 3600 # Time (in seconds) the apt cache stays valid 5 | apt_install_recommends: no # whether or not to install the "recommended" packages 6 | apt_install_suggests: no # whether or not to install the "suggested" packages 7 | apt_autoremove: yes # remove packages that are no longer needed for dependencies 8 | apt_autoclean: yes # remove .deb files for packages no longer on your system 9 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/files/etc_apt_sources.list: -------------------------------------------------------------------------------- 1 | # See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to 2 | # newer versions of the distribution. 3 | deb http://us.archive.ubuntu.com/ubuntu/ precise main restricted 4 | deb-src http://us.archive.ubuntu.com/ubuntu/ precise main restricted 5 | 6 | ## Major bug fix updates produced after the final release of the 7 | ## distribution. 8 | deb http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted 9 | deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates main restricted 10 | 11 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 12 | ## team. Also, please note that software in universe WILL NOT receive any 13 | ## review or updates from the Ubuntu security team. 14 | deb http://us.archive.ubuntu.com/ubuntu/ precise universe 15 | deb-src http://us.archive.ubuntu.com/ubuntu/ precise universe 16 | deb http://us.archive.ubuntu.com/ubuntu/ precise-updates universe 17 | deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates universe 18 | 19 | ## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu 20 | ## team, and may not be under a free licence. Please satisfy yourself as to 21 | ## your rights to use the software. Also, please note that software in 22 | ## multiverse WILL NOT receive any review or updates from the Ubuntu 23 | ## security team. 24 | 25 | deb http://us.archive.ubuntu.com/ubuntu/ precise multiverse 26 | deb-src http://us.archive.ubuntu.com/ubuntu/ precise multiverse 27 | deb http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse 28 | deb-src http://us.archive.ubuntu.com/ubuntu/ precise-updates multiverse 29 | 30 | ## N.B. software from this repository may not have been tested as 31 | ## extensively as that contained in the main release, although it includes 32 | ## newer versions of some applications which may provide useful features. 33 | ## Also, please note that software in backports WILL NOT receive any review 34 | ## or updates from the Ubuntu security team. 35 | deb http://us.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse 36 | deb-src http://us.archive.ubuntu.com/ubuntu/ precise-backports main restricted universe multiverse 37 | 38 | deb http://security.ubuntu.com/ubuntu precise-security main restricted 39 | deb-src http://security.ubuntu.com/ubuntu precise-security main restricted 40 | deb http://security.ubuntu.com/ubuntu precise-security universe 41 | deb-src http://security.ubuntu.com/ubuntu precise-security universe 42 | deb http://security.ubuntu.com/ubuntu precise-security multiverse 43 | deb-src http://security.ubuntu.com/ubuntu precise-security multiverse 44 | 45 | ## Uncomment the following two lines to add software from Canonical's 46 | ## 'partner' repository. 47 | ## This software is not part of Ubuntu, but is offered by Canonical and the 48 | ## respective vendors as a service to Ubuntu users. 49 | # deb http://archive.canonical.com/ubuntu precise partner 50 | # deb-src http://archive.canonical.com/ubuntu precise partner 51 | 52 | ## Uncomment the following two lines to add software from Ubuntu's 53 | ## 'extras' repository. 54 | ## This software is not part of Ubuntu, but is offered by third-party 55 | ## developers who want to ship their latest software. 56 | # deb http://extras.ubuntu.com/ubuntu precise main 57 | # deb-src http://extras.ubuntu.com/ubuntu precise main 58 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/meta/.galaxy_install_info: -------------------------------------------------------------------------------- 1 | {install_date: 'Mon Aug 11 05:51:23 2014', version: v1.0.1} 2 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/meta/main.yml: -------------------------------------------------------------------------------- 1 | # file: apt/meta/main.yml 2 | 3 | galaxy_info: 4 | author: pjan vandaele 5 | company: Ansibles 6 | description: Manages apt and executes apt-get update to ensure the local APT package cache is up to date. 7 | min_ansible_version: 1.4 8 | license: MIT 9 | platforms: 10 | - name: Ubuntu 11 | versions: 12 | - all 13 | categories: 14 | - system 15 | 16 | dependencies: [] 17 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/tasks/main.yml: -------------------------------------------------------------------------------- 1 | # file: apt/tasks/main.yml 2 | 3 | - name: APT | Reset the sources list (/etc/apt/sources.list) 4 | copy: 5 | src: etc_apt_sources.list 6 | dest: /etc/apt/sources.list 7 | owner: root 8 | group: root 9 | mode: 0644 10 | when: apt_reset_source_list 11 | 12 | - name: APT | Update the apt cache 13 | apt: 14 | update_cache: yes 15 | cache_valid_time: "{{apt_cache_valid_time}}" 16 | 17 | - name: APT | Remove packages that are no longer needed for dependencies 18 | shell: apt-get -y autoremove 19 | when: apt_autoremove 20 | 21 | - name: APT | Remove .deb files for packages no longer on your system 22 | shell: apt-get -y autoclean 23 | when: apt_autoclean 24 | 25 | - name: APT | Update the general configuration (/etc/apt/apt.conf.ds/10general) 26 | template: 27 | src: etc_apt_apt.conf.d_10general.j2 28 | dest: /etc/apt/apt.conf.d/10general 29 | owner: root 30 | group: root 31 | mode: 0644 32 | 33 | - name: APT | Make sure the required packages are installed 34 | apt: 35 | pkg: "{{item}}" 36 | state: present 37 | with_items: 38 | - python-apt 39 | - unattended-upgrades 40 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/templates/etc_apt_apt.conf.d_10general.j2: -------------------------------------------------------------------------------- 1 | APT::Install-Recommends "{{apt_install_recommends}}"; 2 | APT::Install-Suggests "{{apt_install_suggests}}"; 3 | 4 | APT::Get::Show-Upgraded "true"; 5 | -------------------------------------------------------------------------------- /roles/galaxy/Ansibles.apt/test.yml: -------------------------------------------------------------------------------- 1 | - hosts: all 2 | vars_files: 3 | - 'defaults/main.yml' 4 | tasks: 5 | - include: 'tasks/main.yml' 6 | -------------------------------------------------------------------------------- /roles/galaxy/angstwad.docker_ubuntu/LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /roles/galaxy/angstwad.docker_ubuntu/README.md: -------------------------------------------------------------------------------- 1 | docker_ubuntu 2 | ======== 3 | 4 | Installs Docker on a version higher than Ubuntu 12.04. 5 | This role differs from other roles in that it specifically follows docker.io installation instructions for each Ubuntu version, 12.04 or 13.04+. 6 | 7 | **Please see [this playbook](https://github.com/angstwad/ansible-docker-rackspace) for an example of how to utilize this role.** 8 | 9 | This is an example playbook in which I call two playbooks to launch and display information about a Rackspace Cloud server, on top of which I use the *docker_ubuntu* role to install Docker. 10 | ``` 11 | # Install to an instance running Ubuntu 12.04 12 | - include: rax-servers.yml 13 | vars: 14 | image: "ubuntu-1204-lts-precise-pangolin" 15 | 16 | - name: Install pycurl 17 | hosts: docker 18 | gather_facts: no 19 | tasks: 20 | - name: Install pycurl 21 | apt: pkg=python-pycurl update_cache=yes cache_valid_time=600 22 | 23 | - name: Install Docker on Rax Server 24 | hosts: docker 25 | roles: 26 | - angstwad.docker_ubuntu 27 | 28 | - include: rax-servers-info.yml 29 | ``` 30 | 31 | Requirements 32 | ------------ 33 | 34 | Requires python-pycurl for apt modules. 35 | 36 | Role Variables 37 | -------------- 38 | 39 | These are the defaults, which can be set to present to prevent a reboot if the latest linux-image-extra, cgroup-lite packages are already installed 40 | The following role variables are defined: 41 | 42 | ``` 43 | # Set to present to prevent a reboot if the latest linux-image-extra is already installed 44 | kernel_pkg_state: latest 45 | # Set to present to prevent a reboot if the latest cgroup-lite is already installed 46 | cgroup_lite_pkg_state: latest 47 | # Set to the default port that ssh is running on. Only used if ansible_ssh_port is not defined. 48 | ssh_port: 22 49 | ``` 50 | 51 | Dependencies 52 | ------------ 53 | 54 | None. 55 | 56 | License 57 | ------- 58 | 59 | Apache v2.0 60 | -------------------------------------------------------------------------------- /roles/galaxy/angstwad.docker_ubuntu/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | kernel_pkg_state: latest 3 | cgroup_lite_pkg_state: latest 4 | ssh_port: 22 5 | -------------------------------------------------------------------------------- /roles/galaxy/angstwad.docker_ubuntu/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for docker.ubuntu 3 | - name: Start Docker 4 | service: name=docker state=started -------------------------------------------------------------------------------- /roles/galaxy/angstwad.docker_ubuntu/meta/.galaxy_install_info: -------------------------------------------------------------------------------- 1 | {install_date: 'Mon Aug 11 05:51:24 2014', version: master} 2 | -------------------------------------------------------------------------------- /roles/galaxy/angstwad.docker_ubuntu/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Paul Durivage 4 | description: Docker on Ubuntu greater than 12.04 5 | license: Apache v2.0 6 | min_ansible_version: 1.2 7 | platforms: 8 | - name: Ubuntu 9 | versions: 10 | - precise 11 | - raring 12 | - saucy 13 | - trusty 14 | categories: 15 | - development 16 | - packaging 17 | - system 18 | dependencies: [] 19 | # List your role dependencies here, one per line. Only 20 | # dependencies available via galaxy should be listed here. 21 | # Be sure to remove the '[]' above if you add dependencies 22 | # to this list. 23 | 24 | -------------------------------------------------------------------------------- /roles/galaxy/angstwad.docker_ubuntu/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for docker.ubuntu 3 | - name: Fail if not a new release of Ubuntu 4 | fail: msg="{{ ansible_distribution_version }} is not an acceptable version of Ubuntu for this role" 5 | when: "ansible_distribution_version not in ['12.04', '13.04', '13.10', '14.04']" 6 | 7 | - name: Install raring kernel onto 12.04 8 | apt: 9 | pkg: "{{ item }}" 10 | state: latest 11 | update_cache: yes 12 | cache_valid_time: 600 13 | with_items: 14 | - linux-image-generic-lts-raring 15 | - linux-headers-generic-lts-raring 16 | register: kernel_result 17 | when: "ansible_distribution_version == '12.04'" 18 | 19 | - name: Install latest kernel extras for Ubuntu 13.04+ 20 | apt: 21 | pkg: "linux-image-extra-{{ ansible_kernel }}" 22 | state: "{{ kernel_pkg_state }}" 23 | update_cache: yes 24 | cache_valid_time: 600 25 | when: "ansible_distribution_version != '12.04'" 26 | 27 | # Fix for https://github.com/dotcloud/docker/issues/4568 28 | - name: Install cgroup-lite for Ubuntu 13.10 29 | apt: 30 | pkg: cgroup-lite 31 | state: "{{ cgroup_lite_pkg_state }}" 32 | update_cache: yes 33 | cache_valid_time: 600 34 | register: cgroup_lite_result 35 | when: "ansible_distribution_version == '13.10'" 36 | 37 | - name: Reboot instance 38 | command: /sbin/shutdown -r now 39 | register: reboot_result 40 | when: "(ansible_distribution_version == '12.04' and kernel_result|changed) 41 | or (ansible_distribution_version == '13.10' and cgroup_lite_result|changed)" 42 | 43 | - name: Wait for instance to come online 44 | local_action: 45 | module: wait_for 46 | host: "{{ ansible_ssh_host|default(inventory_hostname) }}" 47 | port: "{{ ansible_ssh_port|default(ssh_port) }}" 48 | delay: 30 49 | timeout: 600 50 | state: started 51 | when: "(ansible_distribution_version == '12.04' and reboot_result|changed) 52 | or (ansible_distribution_version == '13.10' and cgroup_lite_result|changed)" 53 | 54 | - name: Add Docker repository key 55 | apt_key: url="https://get.docker.io/gpg" id="A88D21E9" 56 | 57 | - name: Add Docker repository 58 | apt_repository: 59 | repo: 'deb http://get.docker.io/ubuntu docker main' 60 | update_cache: yes 61 | 62 | - name: Install Docker 63 | apt: pkg=lxc-docker 64 | notify: "Start Docker" 65 | 66 | - name: Check if /etc/default/ufw exists 67 | stat: path=/etc/default/ufw 68 | register: ufw_default_exists 69 | 70 | - name: Change ufw default forward policy from drop to accept 71 | lineinfile: > 72 | dest=/etc/default/ufw 73 | regexp="^DEFAULT_FORWARD_POLICY=" 74 | line='DEFAULT_FORWARD_POLICY="ACCEPT"' 75 | when: ufw_default_exists.stat.exists 76 | 77 | -------------------------------------------------------------------------------- /roles/image_building/hellobaby_image/defaults/main.yml: -------------------------------------------------------------------------------- 1 | hellobaby_base_name: phusion/baseimage 2 | hellobaby_base_tag: "latest" 3 | hellobaby_version: "" 4 | hellobaby_build_dir: /tmp/hellobaby 5 | hellobaby_repo: https://github.com/victorlin/ansibl-docker-hellobaby.git 6 | hellobaby_extra_tag: latest 7 | hellobaby_image_name: hellobaby 8 | hellobaby_image_tag: > 9 | {{ hellobaby_version }} 10 | {%- if hellobaby_iteration -%} 11 | -{{ hellobaby_iteration }} 12 | {%- endif -%} 13 | -------------------------------------------------------------------------------- /roles/image_building/hellobaby_image/meta/main.yml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | - angstwad.docker_ubuntu 3 | -------------------------------------------------------------------------------- /roles/image_building/hellobaby_image/tasks/main.yml: -------------------------------------------------------------------------------- 1 | - assert: 2 | that: 3 | - 'hellobaby_version != ""' 4 | 5 | - name: install apt packages 6 | apt: "name='{{ item }}' state=present" 7 | with_items: 8 | - git 9 | - python-pip 10 | 11 | - name: install docker-py 12 | pip: name=docker-py version=0.3.1 13 | 14 | - name: create build directory 15 | file: > 16 | dest="{{ hellobaby_build_dir }}" 17 | state=directory 18 | 19 | - name: clone hellobaby git repo 20 | git: > 21 | repo="{{ hellobaby_repo }}" 22 | dest="{{ hellobaby_build_dir }}/hellobaby" 23 | version="v{{ hellobaby_version }}" 24 | register: hellobaby_repo 25 | 26 | - name: remove git deploy key 27 | file: dest=/tmp/github_deploy_key state=absent 28 | 29 | - name: archive repo 30 | shell: > 31 | cd "{{ hellobaby_build_dir }}/{{ item }}" && 32 | git archive -o ../{{ item }}.tar HEAD 33 | with_items: 34 | - hellobaby 35 | 36 | - name: generate templates 37 | template: > 38 | src="{{ item.src }}" 39 | dest="{{ hellobaby_build_dir }}/{{ item.dest }}" 40 | with_items: 41 | - { src: "Dockerfile", dest: "Dockerfile" } 42 | - { src: "runapp.sh", dest: "runapp.sh" } 43 | 44 | - name: build image 45 | docker_image: > 46 | name="{{ hellobaby_image_name }}" 47 | tag="{{ hellobaby_image_tag }}" 48 | path="{{ hellobaby_build_dir }}" 49 | state=build 50 | 51 | - name: tag 52 | command: > 53 | docker tag -f 54 | {{ hellobaby_image_name }}:{{ hellobaby_image_tag }} 55 | {{ hellobaby_image_name }}:{{ hellobaby_extra_tag }} 56 | when: hellobaby_extra_tag != '' 57 | -------------------------------------------------------------------------------- /roles/image_building/hellobaby_image/templates/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM {{ hellobaby_base_name }}:{{ hellobaby_base_tag }} 2 | MAINTAINER Victor Lin 3 | 4 | # update apt and install dependencies 5 | RUN apt-get -qq update 6 | RUN apt-get install -y python python-dev python-pip python-virtualenv 7 | RUN apt-get install -y build-essential gcc 8 | RUN easy_install -U setuptools 9 | 10 | # install packages 11 | ADD hellobaby.tar /srv/hellobaby 12 | RUN echo "{{ hellobaby_image_tag }}" > /srv/hellobaby/hellobaby/version.txt 13 | RUN echo "{{ hellobaby_repo.after }}" > /srv/hellobaby/hellobaby/git_revision.txt 14 | RUN pip install -e /srv/hellobaby 15 | 16 | # run hellobaby app as a runit service 17 | RUN mkdir /etc/service/hellobaby 18 | ADD runapp.sh /etc/service/hellobaby/run 19 | RUN chmod +x /etc/service/hellobaby/run 20 | 21 | EXPOSE 6543 22 | 23 | # Clean up APT when done. 24 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 25 | -------------------------------------------------------------------------------- /roles/image_building/hellobaby_image/templates/runapp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | exec pserve /srv/hellobaby/development.ini 3 | --------------------------------------------------------------------------------