├── .travis.yml ├── LICENSE ├── README.md ├── defaults └── main.yml ├── meta └── main.yml ├── tasks ├── configuration.yml ├── main.yml └── os_family │ ├── Alpine.yml │ ├── Arch.yml │ ├── CentOS.yml │ ├── Debian.yml │ ├── Fedora.yml │ ├── RHEL.yml │ ├── RedHat.yml │ └── Suse.yml └── tests ├── inventory └── test.yml /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | # Use the new container infrastructure 6 | sudo: false 7 | 8 | # Install ansible 9 | addons: 10 | apt: 11 | packages: 12 | - python-pip 13 | 14 | install: 15 | # Install ansible 16 | - pip install ansible 17 | 18 | # Check ansible version 19 | - ansible --version 20 | 21 | # Create ansible.cfg with correct roles_path 22 | - printf '[defaults]\nroles_path=../' >ansible.cfg 23 | 24 | script: 25 | # Basic role syntax check 26 | - ansible-playbook tests/test.yml -i tests/inventory --syntax-check 27 | 28 | notifications: 29 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Alejandro Baez 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Docker 2 | ========= 3 | [![license][2i]][2p] 4 | 5 | Install docker with docker-compose for a number of linux variants. 6 | 7 | Variables 8 | --------- 9 | 10 | There are two variables that should be changed if you are using RHEL or SLES. 11 | They are simply the repo url and [version][3] for the enterprise edition of docker. 12 | If you are using any of the other distros, carry along, no need to change. 13 | 14 | ``` yaml 15 | # default/main.yml 16 | ee: 17 | url: "string for the url of your repo subscription" 18 | version: 7 # Optional for RHEL and not required for SLES at all. 19 | ``` 20 | 21 | Usage 22 | ----- 23 | 24 | All you need to do is make sure you are running the role as a privileged user and append to playbook like so:: 25 | 26 | ``` yaml 27 | - hosts: servers 28 | roles: 29 | - abaez.docker 30 | ``` 31 | 32 | Author Information 33 | ------------------ 34 | 35 | [Alejandro Baez][1] 36 | 37 | [1]: https://keybase.io/baez 38 | [2i]: https://img.shields.io/badge/license-BSD_2-blue.svg 39 | [2p]: ./LICENSE 40 | [3]: https://docs.docker.com/engine/installation/linux/rhel/#install-using-the-repository 41 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | ee: 4 | url: "Some(URL)" 5 | # check 6 | version: 7 7 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | galaxy_info: 2 | author: Alejandro Baez 3 | description: Install docker with docker-compose for RedHat, Debian, and Suse variants. 4 | 5 | # If the issue tracker for your role is not on github, uncomment the 6 | # next line and provide a value 7 | issue_tracker_url: https://bitbucket.org/a_baez/ansible-role-docker/issues 8 | 9 | license: BSD 10 | 11 | min_ansible_version: 2.0 12 | 13 | # Optionally specify the branch Galaxy will use when accessing the GitHub 14 | # repo for this role. During role install, if no tags are available, 15 | # Galaxy will use this branch. During import Galaxy will access files on 16 | # this branch. If travis integration is cofigured, only notification for this 17 | # branch will be accepted. Otherwise, in all cases, the repo's default branch 18 | # (usually master) will be used. 19 | #github_branch: 20 | 21 | # Below are all platforms currently available. Just uncomment 22 | # the ones that apply to your role. If you don't see your 23 | # platform on this list, let us know and we'll get it added! 24 | # 25 | platforms: 26 | - name: Archlinux 27 | versions: 28 | - all 29 | - name: EL 30 | versions: 31 | - all 32 | - name: Fedora 33 | versions: 34 | - 24 35 | - 25 36 | - name: opensuse 37 | versions: 38 | - all 39 | - name: Ubuntu 40 | versions: 41 | - all 42 | - name: SLES 43 | versions: 44 | - all 45 | - name: Debian 46 | versions: 47 | - all 48 | - name: Alpine 49 | versions: 50 | - all 51 | 52 | galaxy_tags: 53 | - docker 54 | - opensuse 55 | - fedora 56 | - redhat 57 | - centos 58 | - ubuntu 59 | - arch 60 | - alpine 61 | 62 | dependencies: [] 63 | # List your role dependencies here, one per line. 64 | # Be sure to remove the '[]' above if you add dependencies 65 | # to this list. 66 | -------------------------------------------------------------------------------- /tasks/configuration.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: enable docker 3 | service: enabled=yes name=docker 4 | 5 | - name: start docker 6 | service: 7 | name=docker 8 | state=restarted 9 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install docker and dependencies 3 | include: "os_family/{{ ansible_os_family }}.yml" 4 | 5 | - name: Configure docker 6 | include: "configuration.yml" 7 | -------------------------------------------------------------------------------- /tasks/os_family/Alpine.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install the required 3 | apk: name="{{ item }}" state=present 4 | with_items: 5 | - docker 6 | - py-pip 7 | 8 | - name: install python things 9 | pip: name="{{ item }}" state=present 10 | with_items: 11 | - docker-compose 12 | - docker-py 13 | -------------------------------------------------------------------------------- /tasks/os_family/Arch.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install the required 3 | pacman: name="{{ item }}" state=updated 4 | with_items: 5 | - docker 6 | - docker-compose 7 | - docker-machine 8 | - python-docker-py 9 | -------------------------------------------------------------------------------- /tasks/os_family/CentOS.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: install yum-utils 4 | yum: 5 | name: yum-utils 6 | state: present 7 | 8 | - name: install docker repository 9 | command: yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 10 | 11 | - name: make sure docker from distro is not installed 12 | yum: 13 | name: "{{ item }}" 14 | state: absent 15 | with_items: 16 | - docker 17 | - docker-common 18 | - container-selinux 19 | - docker-selinux 20 | - docker-engine 21 | 22 | - name: Install docker 23 | yum: 24 | name: "{{ item }}" 25 | state: latest 26 | with_items: 27 | - docker-ce 28 | - python-docker-py 29 | 30 | - name: making sure pip installed 31 | shell: curl -sSL https://bootstrap.pypa.io/get-pip.py | python 32 | -------------------------------------------------------------------------------- /tasks/os_family/Debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Install dependencies 4 | apt: 5 | name: [ 6 | python, 7 | curl, 8 | apt-transport-https, 9 | ca-certificates, 10 | gnupg2, 11 | software-properties-common, 12 | ] 13 | state: present 14 | 15 | - name: remove old docker 16 | apt: 17 | name: [ 18 | docker, 19 | docker-engine, 20 | docker.io, 21 | ] 22 | state: absent 23 | 24 | - name: extra packages for Ubuntu 25 | apt: 26 | name: linux-image-extra-virtual 27 | state: present 28 | when: ansible_distribution == "Ubuntu" 29 | 30 | - name: add key id 31 | apt_key: 32 | url: "https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg" 33 | state: present 34 | 35 | - name: add docker repository 36 | apt_repository: 37 | repo: "deb [arch=amd64] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release | lower }} stable" 38 | filename: docker 39 | state: present 40 | 41 | - name: install docker 42 | apt: 43 | name: docker-ce 44 | update_cache: yes 45 | state: present 46 | 47 | - name: install pip 48 | shell: curl -sSL https://bootstrap.pypa.io/get-pip.py | python 49 | 50 | - name: install docker-py and docker-compose 51 | pip: 52 | name: [ 53 | docker-py, 54 | docker-compose, 55 | ] 56 | state: present -------------------------------------------------------------------------------- /tasks/os_family/Fedora.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: make sure dnf-plugins.core installed 4 | dnf: 5 | name: dnf-plugins-core 6 | state: present 7 | 8 | - name: install docker repository 9 | command: dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo 10 | 11 | - name: make sure docker from distro is not installed 12 | yum: 13 | name: "{{ item }}" 14 | state: absent 15 | with_items: 16 | - docker 17 | - docker-common 18 | - container-selinux 19 | - docker-selinux 20 | - docker-engine 21 | 22 | - name: install docker 23 | dnf: 24 | name: "{{ item }}" 25 | state: present 26 | with_items: 27 | - docker-ce 28 | - python-docker-py 29 | - python-pip 30 | -------------------------------------------------------------------------------- /tasks/os_family/RHEL.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: make sure docker from distro is not installed 4 | yum: 5 | name: "{{ item }}" 6 | state: absent 7 | with_items: 8 | - docker 9 | - docker-common 10 | - container-selinux 11 | - docker-selinux 12 | - docker-engine 13 | 14 | - name: append Docker EE url 15 | shell: "echo {{ item }}" 16 | with_items: 17 | - "{{ ee.url }} > /etc/yum/vars/dockerurl" 18 | - "{{ ee.version }} > /etc/yum/vars/dockerosversion" 19 | 20 | - name: install yum-utils 21 | yum: 22 | name: yum-utils 23 | state: present 24 | 25 | - name: install docker repository 26 | command: yum-config-manager --add-repo "{{ ee.url }}/docker-ee.repo" 27 | 28 | - name: Install docker 29 | yum: 30 | name: "{{ item }}" 31 | state: present 32 | with_items: 33 | - docker-ee 34 | - python-docker-py 35 | 36 | - name: making sure pip installed 37 | shell: curl -sSL https://bootstrap.pypa.io/get-pip.py | python 38 | -------------------------------------------------------------------------------- /tasks/os_family/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Run the Fedora based install 4 | include: "Fedora.yml" 5 | when: ansible_distribution == "Fedora" 6 | 7 | - name: Run the RedHat based install 8 | include: "RHEL.yml" 9 | when: ansible_distribution == "RedHat" 10 | 11 | - name: Run the Centos based install 12 | include: "CentOS.yml" 13 | when: ansible_distribution == "CentOS" 14 | 15 | - name: Install docker-compose through pip 16 | pip: name=docker-compose state=latest 17 | -------------------------------------------------------------------------------- /tasks/os_family/Suse.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install docker 3 | zypper: name="{{ item }}" state=present 4 | with_items: 5 | - docker 6 | - python-docker-py 7 | 8 | - name: docker extra modules 9 | zypper: name="{{ item }}" state=present 10 | with_items: 11 | - yast2-docker 12 | - docker-compose 13 | -------------------------------------------------------------------------------- /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | remote_user: root 4 | roles: 5 | - ../ 6 | --------------------------------------------------------------------------------