├── .ansible-lint ├── .clog.toml ├── .editorconfig ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── Vagrantfile ├── ansible.cfg ├── defaults └── main.yml ├── handlers └── main.yml ├── meta ├── main.yml └── readme.yml ├── tasks ├── config.yml ├── install.yml ├── install │ ├── centos.yml │ ├── suse.yml │ └── ubuntu.yml ├── main.yml ├── manage.yml └── service.yml ├── templates ├── etc-default-docker.j2 └── etc-logrotate.d-docker.j2 └── tests └── main.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | exclude_paths: 2 | - ./meta/readme.yml 3 | skip_list: 4 | - '106' # Role name {} does not match ``^[a-z][a-z0-9_]+$`` pattern 5 | -------------------------------------------------------------------------------- /.clog.toml: -------------------------------------------------------------------------------- 1 | [clog] 2 | changelog = "CHANGELOG.md" 3 | repository = "https://github.com/weareinteractive/ansible-docker" 4 | from-latest-tag = true 5 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | # Change these settings to your own preference 9 | indent_size = 2 10 | indent_style = space 11 | 12 | # We recommend you to keep these unchanged 13 | charset = utf-8 14 | end_of_line = lf 15 | insert_final_newline = true 16 | trim_trailing_whitespace = true 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.retry 3 | .DS_Store 4 | .vagrant 5 | .vscode 6 | .idea 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | language: python 4 | python: "2.7" 5 | before_install: 6 | - sudo apt-get update -qq 7 | - sudo apt-get install -qq python-apt python-pycurl aptitude 8 | install: 9 | - pip install ansible 10 | script: 11 | - echo localhost > inventory 12 | - ln -s ansible-docker ../weareinteractive.docker 13 | - ansible-playbook --syntax-check -i inventory tests/main.yml 14 | - ansible-playbook -i inventory tests/main.yml --connection=local --become -vvvv 15 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## 1.12.0 (2021-01-19) 3 | 4 | 5 | #### Features 6 | 7 | * configured docker ce epository url as variables to allow use of a local mirror or a private repo. 8 | 9 | 10 | 11 | ### 1.11.1 (2019-01-28) 12 | 13 | 14 | #### Bug Fixes 15 | 16 | * fix debian distribution release name ([06b78d47](https://github.com/weareinteractive/ansible-docker/commit/06b78d47b3f509b790940ed71bc59d02a3b3aef6)) 17 | 18 | 19 | 20 | 21 | ## 1.11.0 (2018-11-11) 22 | 23 | 24 | #### Features 25 | 26 | * update installation ([3f98f4a8](https://github.com/weareinteractive/ansible-docker/commit/3f98f4a8f9d9e9b71b93d5bd1efa575a221e57f2)) 27 | 28 | 29 | 30 | 31 | ## 1.10.0 (2018-10-25) 32 | 33 | 34 | #### Features 35 | 36 | * update min ansible version ([cd3a797f](https://github.com/weareinteractive/ansible-docker/commit/cd3a797f3598c36b53e6acb50e740593f65b926e)) 37 | * switch galaxy namespace ([a8dd80a4](https://github.com/weareinteractive/ansible-docker/commit/a8dd80a4bed697b8efa43bbaa4e2552406738197)) 38 | 39 | 40 | 41 | 42 | ## 1.9.0 (2017-06-21) 43 | 44 | 45 | #### Features 46 | 47 | * add centos support ([45cef76d](https://github.com/weareinteractive/ansible-docker/commit/45cef76daa06970fe16ee8f357dd9f5c87c43071)) 48 | 49 | 50 | 51 | 52 | ## 1.8.0 (2017-05-26) 53 | 54 | 55 | #### Features 56 | 57 | * support container labels ([29441a28](https://github.com/weareinteractive/ansible-docker/commit/29441a28a48518afb7def41e05f6c83dde1ef4db)) 58 | 59 | 60 | 61 | 62 | ## 1.7.0 (2017-03-27) 63 | 64 | 65 | #### Features 66 | 67 | * update meta info to use ansible 2.0 ([62e6301a](https://github.com/weareinteractive/ansible-docker/commit/62e6301a485678eec365a532d99c515502072472)) 68 | * add docker_pip_dependencies ([3abd25f6](https://github.com/weareinteractive/ansible-docker/commit/3abd25f60063c4a1fe0b1867422c9f3df8934433)) 69 | * use docker_container instead obsolete docker ([cd0b0974](https://github.com/weareinteractive/ansible-docker/commit/cd0b0974c301b23c94e0408e8b903cd2737510af)) 70 | * update tests sudo to become ([bff2dc35](https://github.com/weareinteractive/ansible-docker/commit/bff2dc3513fb4f548da207d238f421edec9f1521)) 71 | 72 | 73 | 74 | 75 | ### 1.6.1 (2016-02-29) 76 | 77 | 78 | #### Features 79 | 80 | * don't use bare variable names ([026b3f98](https://github.com/weareinteractive/ansible-docker/commit/026b3f988217ed6c74efbe6c362295fc62b1efdf)) 81 | 82 | 83 | 84 | 85 | ## 1.6.0 (2015-11-30) 86 | 87 | 88 | #### Features 89 | 90 | * using ansible-role to generate README ([e6a93ed8](https://github.com/weareinteractive/ansible-docker/commit/e6a93ed837e92ad85fc5ec040fe38afb5417771f)) 91 | * adds CHANGELOG ([3b2913da](https://github.com/weareinteractive/ansible-docker/commit/3b2913da9e5b03c5ad66b7c3e277cf75ac34e050)) 92 | * adds opensuse support ([f93b5f21](https://github.com/weareinteractive/ansible-docker/commit/f93b5f2104e6a6154d95ace2b3fd5824e7ad1d3d)) 93 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) We Are Interactive 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | docs: 2 | ansible-role docgen 3 | 4 | lint: 5 | ansible-lint . 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible weareinteractive.docker role 2 | 3 | [![Build Status](https://img.shields.io/travis/weareinteractive/ansible-docker.svg)](https://travis-ci.org/weareinteractive/ansible-docker) 4 | [![Galaxy](http://img.shields.io/badge/galaxy-weareinteractive.docker-blue.svg)](https://galaxy.ansible.com/list#/roles/3275) 5 | [![GitHub Tags](https://img.shields.io/github/tag/weareinteractive/ansible-docker.svg)](https://github.com/weareinteractive/ansible-docker) 6 | [![GitHub Stars](https://img.shields.io/github/stars/weareinteractive/ansible-docker.svg)](https://github.com/weareinteractive/ansible-docker) 7 | 8 | > `weareinteractive.docker` is an [Ansible](http://www.ansible.com) role which: 9 | > 10 | > * installs docker 11 | > * configures docker 12 | > * adds logrotate for docker container logs 13 | 14 | **Note:** 15 | 16 | > Since Ansible Galaxy switched all role names to the organization name, this role has moved from `franklinkim.docker` to `weareinteractive.docker`! 17 | 18 | ## Installation 19 | 20 | Using `ansible-galaxy`: 21 | 22 | ```shell 23 | $ ansible-galaxy install weareinteractive.docker 24 | ``` 25 | 26 | Using `requirements.yml`: 27 | 28 | ```yaml 29 | - src: weareinteractive.docker 30 | ``` 31 | 32 | Using `git`: 33 | 34 | ```shell 35 | $ git clone https://github.com/weareinteractive/ansible-docker.git weareinteractive.docker 36 | ``` 37 | 38 | ## Dependencies 39 | 40 | * Ansible >= 2.4 41 | 42 | ## Variables 43 | 44 | Here is a list of all the default variables for this role, which are also available in `defaults/main.yml`. 45 | 46 | ```yaml 47 | --- 48 | # For more information about handlers see: 49 | # http://www.ansibleworks.com/docs/playbooks.html#handlers-running-operations-on-change 50 | # 51 | # pip dependencies 52 | # docker_pip_dependencies: 53 | # - name: docker-py 54 | # version: 1.9.0 55 | # docker_options: 56 | # - "--dns 8.8.4.4" 57 | # docker_containers: 58 | # - image: foo/bar 59 | # count: ... 60 | # command: ... 61 | # env: ... 62 | # expose: ... 63 | # hostname: ... 64 | # labels: ... 65 | # links: ... 66 | # name: ... 67 | # ports: ... 68 | # privileged: ... 69 | # pull: ... 70 | # state: ... 71 | # volumes: ... 72 | # volumes_from: ... 73 | # 74 | 75 | # apt package 76 | docker_package: docker-ce 77 | # pip dependencies 78 | docker_pip_dependencies: 79 | - docker-py 80 | # start on boot 81 | docker_service_enabled: yes 82 | # current state: started, stopped 83 | docker_service_state: started 84 | # docker default options 85 | docker_options: [] 86 | # list of images (http://docs.ansible.com/docker_image_module.html) 87 | docker_images: [] 88 | # list of containers (http://docs.ansible.com/docker_module.html) 89 | docker_containers: [] 90 | # centos docker ce private repository url 91 | centos_docker_ce_private_repo: 'https://download.docker.com/linux/centos/7/$basearch/stable' 92 | centos_docker_ce_private_repo_gpg: 'https://download.docker.com/linux/centos/gpg' 93 | # debian docker ce private repository url 94 | debian_docker_ce_private_repo: 'https://download.docker.com/linux/{{ ansible_distribution | lower }}' 95 | debian_docker_ce_private_repo_gpg: 'https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg' 96 | ``` 97 | 98 | ## Handlers 99 | 100 | These are the handlers that are defined in `handlers/main.yml`. 101 | 102 | ```yaml 103 | --- 104 | 105 | - name: restart docker 106 | service: name=docker state=restarted 107 | when: docker_service_state != 'stopped' 108 | 109 | ``` 110 | 111 | 112 | ## Usage 113 | 114 | This is an example playbook: 115 | 116 | ```yaml 117 | --- 118 | 119 | - hosts: all 120 | become: yes 121 | roles: 122 | - weareinteractive.docker 123 | vars: 124 | docker_options: 125 | - "--bip=10.0.3.1/24" 126 | docker_pip_dependencies: 127 | - name: docker-py 128 | version: 1.9.0 129 | 130 | ``` 131 | 132 | 133 | ## Testing 134 | 135 | ```shell 136 | $ git clone https://github.com/weareinteractive/ansible-docker.git 137 | $ cd ansible-docker 138 | $ make test 139 | ``` 140 | 141 | ## Contributing 142 | In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests and examples for any new or changed functionality. 143 | 144 | 1. Fork it 145 | 2. Create your feature branch (`git checkout -b my-new-feature`) 146 | 3. Commit your changes (`git commit -am 'Add some feature'`) 147 | 4. Push to the branch (`git push origin my-new-feature`) 148 | 5. Create new Pull Request 149 | 150 | *Note: To update the `README.md` file please install and run `ansible-role`:* 151 | 152 | ```shell 153 | $ gem install ansible-role 154 | $ ansible-role docgen 155 | ``` 156 | 157 | ## License 158 | Copyright (c) We Are Interactive under the MIT license. 159 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | $script = <<-SCRIPT 5 | distribution=$(cat /etc/issue | head -n +1 | awk '{print $1}') 6 | if [ "$distribution" = "Ubuntu" ]; then 7 | sudo apt-get update 8 | sudo apt-get install -y python 9 | elif [ "$distribution" = "CentOS" ]; then 10 | echo "done" 11 | fi 12 | SCRIPT 13 | 14 | Vagrant.configure("2") do |config| 15 | #config.vbguest.no_remote = true 16 | #config.vbguest.auto_update = false 17 | 18 | # Ubuntui 19 | 20 | config.vm.define 'bionic' do |instance| 21 | instance.vm.box = 'ubuntu/bionic64' 22 | end 23 | 24 | config.vm.define 'xenial' do |instance| 25 | instance.vm.box = 'ubuntu/xenial64' 26 | end 27 | 28 | # CentOS 29 | 30 | config.vm.define 'centos7' do |instance| 31 | instance.vm.box = 'centos/7' 32 | end 33 | 34 | config.vm.provision "shell", inline: $script 35 | 36 | 37 | # View the documentation for the provider you're using for more 38 | # information on available options. 39 | config.vm.provision "ansible" do |ansible| 40 | ansible.playbook = "tests/main.yml" 41 | ansible.verbose = 'vv' 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = ../ -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # For more information about handlers see: 3 | # http://www.ansibleworks.com/docs/playbooks.html#handlers-running-operations-on-change 4 | # 5 | # pip dependencies 6 | # docker_pip_dependencies: 7 | # - name: docker-py 8 | # version: 1.9.0 9 | # docker_options: 10 | # - "--dns 8.8.4.4" 11 | # docker_containers: 12 | # - image: foo/bar 13 | # count: ... 14 | # command: ... 15 | # env: ... 16 | # expose: ... 17 | # hostname: ... 18 | # labels: ... 19 | # links: ... 20 | # name: ... 21 | # ports: ... 22 | # privileged: ... 23 | # pull: ... 24 | # state: ... 25 | # volumes: ... 26 | # volumes_from: ... 27 | # 28 | 29 | # apt package 30 | docker_package: docker-ce 31 | # pip dependencies 32 | docker_pip_dependencies: 33 | - docker-py 34 | # start on boot 35 | docker_service_enabled: yes 36 | # current state: started, stopped 37 | docker_service_state: started 38 | # docker default options 39 | docker_options: [] 40 | # list of images (http://docs.ansible.com/docker_image_module.html) 41 | docker_images: [] 42 | # list of containers (http://docs.ansible.com/docker_module.html) 43 | docker_containers: [] 44 | # centos docker ce private repository url 45 | centos_docker_ce_private_repo: 'https://download.docker.com/linux/centos/7/$basearch/stable' 46 | centos_docker_ce_private_repo_gpg: 'https://download.docker.com/linux/centos/gpg' 47 | # debian docker ce private repository url 48 | debian_docker_ce_private_repo: 'https://download.docker.com/linux/{{ ansible_distribution | lower }}' 49 | debian_docker_ce_private_repo_gpg: 'https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg' -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: restart docker 4 | service: name=docker state=restarted 5 | when: docker_service_state != 'stopped' 6 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: franklin 4 | company: We Are Interactive 5 | description: Installs and manages docker 6 | min_ansible_version: 2.4 7 | license: MIT 8 | # Optionally specify the branch Galaxy will use when accessing the GitHub 9 | # repo for this role. During role install, if no tags are available, 10 | # Galaxy will use this branch. During import Galaxy will access files on 11 | # this branch. If travis integration is cofigured, only notification for this 12 | # branch will be accepted. Otherwise, in all cases, the repo's default branch 13 | # (usually master) will be used. 14 | github_branch: master 15 | # 16 | # Below are all platforms currently available. Just uncomment 17 | # the ones that apply to your role. If you don't see your 18 | # platform on this list, let us know and we'll get it added! 19 | # 20 | platforms: 21 | - name: EL 22 | versions: 23 | - all 24 | # - 5 25 | # - 6 26 | # - 7 27 | #- name: GenericUNIX 28 | # versions: 29 | # - all 30 | # - any 31 | #- name: Solaris 32 | # versions: 33 | # - all 34 | # - 10 35 | # - 11.0 36 | # - 11.1 37 | # - 11.2 38 | # - 11.3 39 | #- name: Fedora 40 | # versions: 41 | # - all 42 | # - 16 43 | # - 17 44 | # - 18 45 | # - 19 46 | # - 20 47 | # - 21 48 | # - 22 49 | # - 23 50 | #- name: Windows 51 | # versions: 52 | # - all 53 | # - 2012R2 54 | #- name: SmartOS 55 | # versions: 56 | # - all 57 | # - any 58 | - name: opensuse 59 | versions: 60 | - all 61 | # - 12.1 62 | # - 12.2 63 | # - 12.3 64 | # - 13.1 65 | # - 13.2 66 | #- name: Amazon 67 | # versions: 68 | # - all 69 | # - 2013.03 70 | # - 2013.09 71 | #- name: GenericBSD 72 | # versions: 73 | # - all 74 | # - any 75 | #- name: FreeBSD 76 | # versions: 77 | # - all 78 | # - 10.0 79 | # - 10.1 80 | # - 10.2 81 | # - 8.0 82 | # - 8.1 83 | # - 8.2 84 | # - 8.3 85 | # - 8.4 86 | # - 9.0 87 | # - 9.1 88 | # - 9.1 89 | # - 9.2 90 | # - 9.3 91 | - name: Ubuntu 92 | versions: 93 | - all 94 | # - lucid 95 | # - maverick 96 | # - natty 97 | # - oneiric 98 | # - precise 99 | # - quantal 100 | # - raring 101 | # - saucy 102 | # - trusty 103 | # - utopic 104 | # - vivid 105 | # - wily 106 | #- name: SLES 107 | # versions: 108 | # - all 109 | # - 10SP3 110 | # - 10SP4 111 | # - 11 112 | # - 11SP1 113 | # - 11SP2 114 | # - 11SP3 115 | #- name: GenericLinux 116 | # versions: 117 | # - all 118 | # - any 119 | - name: Debian 120 | versions: 121 | - all 122 | # - etch 123 | # - jessie 124 | # - lenny 125 | # - squeeze 126 | # - wheezy 127 | # 128 | # List tags for your role here, one per line. A tag is 129 | # a keyword that describes and categorizes the role. 130 | # Users find roles by searching for tags. Be sure to 131 | # remove the '[]' above if you add tags to this list. 132 | # 133 | # NOTE: A tag is limited to a single word comprised of 134 | # alphanumeric characters. Maximum 20 tags per role. 135 | galaxy_tags: 136 | - docker 137 | # List your role dependencies here, one per line. Only 138 | # dependencies available via galaxy should be listed here. 139 | # Be sure to remove the '[]' above if you add dependencies 140 | # to this list. 141 | dependencies: [] 142 | -------------------------------------------------------------------------------- /meta/readme.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | galaxy_name: weareinteractive.docker 4 | github_user: weareinteractive 5 | github_name: ansible-docker 6 | badges: | 7 | [![Build Status](https://img.shields.io/travis/weareinteractive/ansible-docker.svg)](https://travis-ci.org/weareinteractive/ansible-docker) 8 | [![Galaxy](http://img.shields.io/badge/galaxy-weareinteractive.docker-blue.svg)](https://galaxy.ansible.com/list#/roles/3275) 9 | [![GitHub Tags](https://img.shields.io/github/tag/weareinteractive/ansible-docker.svg)](https://github.com/weareinteractive/ansible-docker) 10 | [![GitHub Stars](https://img.shields.io/github/stars/weareinteractive/ansible-docker.svg)](https://github.com/weareinteractive/ansible-docker) 11 | description: | 12 | > * installs docker 13 | > * configures docker 14 | > * adds logrotate for docker container logs 15 | 16 | **Note:** 17 | 18 | > Since Ansible Galaxy switched all role names to the organization name, this role has moved from `franklinkim.docker` to `weareinteractive.docker`! 19 | -------------------------------------------------------------------------------- /tasks/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Configuring docker 4 | template: 5 | src: etc-default-docker.j2 6 | dest: /etc/default/docker 7 | owner: root 8 | group: root 9 | mode: "0644" 10 | notify: restart docker 11 | 12 | - name: Configuring logrotate 13 | template: 14 | src: etc-logrotate.d-docker.j2 15 | dest: /etc/logrotate.d/docker 16 | owner: root 17 | group: root 18 | mode: "0644" 19 | -------------------------------------------------------------------------------- /tasks/install.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - import_tasks: install/ubuntu.yml 4 | when: ansible_distribution == 'Debian' or ansible_distribution == 'Ubuntu' 5 | 6 | - import_tasks: install/suse.yml 7 | when: ansible_distribution == 'Suse' or ansible_distribution == 'openSUSE' 8 | 9 | - import_tasks: install/centos.yml 10 | when: ansible_distribution == 'CentOS' 11 | 12 | - name: Installing packages 13 | package: 14 | name: "{{ packages }}" 15 | state: present 16 | vars: 17 | packages: 18 | - python-pip 19 | - "{{ docker_package }}" 20 | 21 | - name: Installing Ansible PIP dependencies 22 | pip: 23 | name: "{{ item.name | default(item) }}" 24 | state: present 25 | version: "{{ item.version | default(omit) }}" 26 | with_items: "{{ docker_pip_dependencies }}" 27 | -------------------------------------------------------------------------------- /tasks/install/centos.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Installing dependencies 4 | yum: 5 | name: "{{ packages }}" 6 | state: present 7 | vars: 8 | packages: 9 | - lvm2 10 | - yum-utils 11 | - epel-release 12 | - device-mapper-persistent-data 13 | 14 | 15 | - name: Adding YUM repository 16 | yum_repository: 17 | name: docker-ce-stable 18 | description: Docker CE Stable - $basearch 19 | baseurl: "{{ centos_docker_ce_private_repo }}" 20 | enabled: yes 21 | gpgcheck: yes 22 | gpgkey: "{{ centos_docker_ce_private_repo_gpg }}" 23 | 24 | -------------------------------------------------------------------------------- /tasks/install/suse.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Installing dependencies 4 | zypper: 5 | name: ca-certificates 6 | state: present 7 | -------------------------------------------------------------------------------- /tasks/install/ubuntu.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | # Fix for debian distribution 4 | - name: Set Ansible distribution release 5 | set_fact: 6 | ansible_distribution_release: '{{ ansible_facts["distribution_major_version"].split("/")[0] 7 | if (ansible_facts["distribution_major_version"].split("/") | length) > 1 8 | else ansible_facts["distribution_release"] }}' 9 | 10 | - name: Installing dependencies 11 | apt: 12 | name: "{{ packages }}" 13 | state: present 14 | vars: 15 | packages: 16 | - ca-certificates 17 | - apt-transport-https 18 | - software-properties-common 19 | 20 | - name: Adding APT key 21 | apt_key: 22 | id: 0EBFCD88 23 | url: "{{ debian_docker_ce_private_repo_gpg }}" 24 | 25 | - name: Adding APT repository 26 | apt_repository: 27 | repo: "deb [arch=amd64] {{ debian_docker_ce_private_repo }} {{ ansible_distribution_release }} stable" 28 | update_cache: yes 29 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - import_tasks: config.yml 4 | tags: 5 | - development 6 | - docker 7 | - config 8 | - docker-config 9 | 10 | - import_tasks: install.yml 11 | tags: 12 | - development 13 | - docker 14 | - install 15 | - docker-install 16 | 17 | - import_tasks: manage.yml 18 | tags: 19 | - development 20 | - docker 21 | - manage 22 | - docker-manage 23 | 24 | - import_tasks: service.yml 25 | tags: 26 | - development 27 | - docker 28 | - service 29 | - docker-service 30 | -------------------------------------------------------------------------------- /tasks/manage.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Managing images 4 | docker_image: 5 | name: "{{ item.name if item.name is defined else item }}" 6 | nocache: "{{ item.nocache | default(omit) }}" 7 | path: "{{ item.path | default(omit) }}" 8 | state: "{{ item.state | default(omit) }}" 9 | tag: "{{ item.tag | default(omit) }}" 10 | timeout: "{{ item.timeout | default(omit) }}" 11 | with_items: "{{ docker_images }}" 12 | register: docker_images_stat 13 | failed_when: docker_images_stat.msg and "Image builded:" not in docker_images_stat.msg 14 | 15 | - name: Managing containers 16 | docker_container: 17 | count: "{{ item.count | default(omit) }}" 18 | command: "{{ item.command | default(omit) }}" 19 | env: "{{ item.env | default(omit) }}" 20 | expose: "{{ item.expose | default(omit) }}" 21 | hostname: "{{ item.hostname | default(omit) }}" 22 | image: "{{ item.image }}" 23 | labels: "{{ item.labels | default(omit) }}" 24 | links: "{{ item.links | default(omit) }}" 25 | name: "{{ item.name | default(omit) }}" 26 | ports: "{{ item.ports | default(omit) }}" 27 | privileged: "{{ item.privileged | default(omit) }}" 28 | pull: "{{ item.pull | default(omit) }}" 29 | state: "{{ item.state | default(omit) }}" 30 | volumes: "{{ item.volumes | default(omit) }}" 31 | volumes_from: "{{ item.volumes_from | default(omit) }}" 32 | with_items: "{{ docker_containers }}" 33 | -------------------------------------------------------------------------------- /tasks/service.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Configuring service 4 | service: 5 | name: docker 6 | enabled: "{{ docker_service_enabled }}" 7 | state: "{{ docker_service_state }}" 8 | -------------------------------------------------------------------------------- /templates/etc-default-docker.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | # Docker Upstart and SysVinit configuration file 3 | 4 | # Customize location of Docker binary (especially for development testing). 5 | #DOCKER="/usr/local/bin/docker" 6 | 7 | # Use DOCKER_OPTS to modify the daemon startup options. 8 | #DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4" 9 | 10 | DOCKER_OPTS="" 11 | {% for option in docker_options | default([]) %} 12 | DOCKER_OPTS="$DOCKER_OPTS {{ option }}" 13 | {% endfor %} 14 | export DOCKER_OPTS 15 | 16 | # If you need Docker to use an HTTP proxy, it can also be specified here. 17 | #export http_proxy="http://127.0.0.1:3128/" 18 | 19 | # This is also a handy place to tweak where Docker's temporary files go. 20 | #export TMPDIR="/mnt/bigdrive/docker-tmp" 21 | -------------------------------------------------------------------------------- /templates/etc-logrotate.d-docker.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | /var/lib/docker/containers/*/*.log { 4 | rotate 7 5 | daily 6 | compress 7 | size=1M 8 | missingok 9 | delaycompress 10 | copytruncate 11 | create 640 root adm 12 | } 13 | -------------------------------------------------------------------------------- /tests/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - hosts: all 4 | become: yes 5 | roles: 6 | - weareinteractive.docker 7 | vars: 8 | docker_options: 9 | - "--bip=10.0.3.1/24" 10 | docker_pip_dependencies: 11 | - name: docker-py 12 | version: 1.9.0 13 | --------------------------------------------------------------------------------