commit 9c7d801eeaf25256ba560330e2d8b282a6026dc2 Author: Robert Kaussow Date: Wed Dec 12 23:25:36 2018 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5c199eb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +# ---> Ansible +*.retry + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3f28a5f --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..62014fe --- /dev/null +++ b/README.md @@ -0,0 +1,54 @@ +# sit-lnx.docker-engine + +Install docker engine. Currently only overlay2 as storage engine is supported. + +**Supported OS** +* RHEL7 + +### Role Variables + +```yaml +--- +dockerengine_package: docker +dockerengine_docker_group_enabled: False + +dockerengine_secure_registries: [] +dockerengine_insecure_registries: [] +dockerengine_block_registries: [] + +# dockerengine_http_proxy: # defaults to not set +# dockerengine_https_proxy: # defaults to not set +# dockerengine_no_proxy: # defaults to not set + +# All storage variables are mandatory. You have to set them correctly! +# dockerengine_storage_pvs: /dev/sdx # defaults to not set +dockerengine_storage_vg: vg_docker +dockerengine_storage_lv: lv_docker +dockerengine_storage_size: 100G +dockerengine_base_dir: /var/lib/docker +``` + +### Examples + +#### Playbook + +```yaml +--- +- hosts: docker-engine + become: true + + roles: + - sit-lnx.docker-engine +``` + +### Dependencies + +* you need the `wrap` custom filter from + +### Maintainer + +[Robert Kaussow](https://gitea.rknet.org/xoxys) + +### License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..0065f5e --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,17 @@ +--- +dockerengine_package: docker +dockerengine_docker_group_enabled: False + +dockerengine_secure_registries: [] +dockerengine_insecure_registries: [] +dockerengine_block_registries: [] + +# dockerengine_http_proxy: # defaults to not set +# dockerengine_https_proxy: # defaults to not set +# dockerengine_no_proxy: # defaults to not set + +# dockerengine_storage_pvs: /dev/sdx # defaults to not set +dockerengine_storage_vg: vg_docker +dockerengine_storage_lv: lv_docker +dockerengine_storage_size: 100G +dockerengine_base_dir: /var/lib/docker diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..0d8edbe --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Restart docker engine + systemd: + state: restarted + name: "{{ dockerengine_package }}" + daemon_reload: yes + enabled: yes + listen: __docker_restart + become: True + become_user: root diff --git a/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..1ae5d35 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,13 @@ +--- +galaxy_info: + author: Robert Kaussow + description: Install Docker Engine + license: MIT + min_ansible_version: 2.4 + platforms: + - name: EL + versions: + - 7 + galaxy_tags: + - docker +dependencies: [] diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..a39340f --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,34 @@ +--- +- block: + - name: Install docker engine + package: + name: "{{ dockerengine_package }}" + state: installed + + - name: Add docker group + group: + name: docker + state: present + notify: __docker_restart + when: dockerengine_docker_group_enabled + + - name: Deploy config files to setup environment + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + owner: root + group: root + mode: 0644 + with_items: + - { src: 'etc/sysconfig/docker.j2', dest: '/etc/sysconfig/{{ dockerengine_package }}' } + - { src: 'etc/sysconfig/docker-storage-setup.j2', dest: '/etc/sysconfig/{{ dockerengine_package }}-storage-setup' } + - { src: 'etc/containers/registries.conf.j2', dest: '/etc/containers/registries.conf' } + notify: __docker_restart + + - name: Ensure docker engine is up and running + service: + name: "{{ dockerengine_package }}" + enabled: True + state: started + become: True + become_user: root diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..a48ceb8 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,2 @@ +--- +- include_tasks: install.yml diff --git a/templates/etc/containers/registries.conf.j2 b/templates/etc/containers/registries.conf.j2 new file mode 100644 index 0000000..47c0358 --- /dev/null +++ b/templates/etc/containers/registries.conf.j2 @@ -0,0 +1,27 @@ +# {{ ansible_managed }} +# This is a system-wide configuration file used to +# keep track of registries for various container backends. +# It adheres to TOML format and does not support recursive +# lists of registries. + +# The default location for this configuration file is /etc/containers/registries.conf. + +# The only valid categories are: 'registries.search', 'registries.insecure', +# and 'registries.block'. + +[registries.search] +#registries = ['registry.access.redhat.com'] +registries = [{{ dockerengine_secure_registries | wrap | join(',') }}] + +# If you need to access insecure registries, add the registry's fully-qualified name. +# An insecure registry is one that does not have a valid SSL certificate or only does HTTP. +[registries.insecure] +registries = [{{ dockerengine_insecure_registries | wrap | join(',') }}] + + +# If you need to block pull access from a registry, uncomment the section below +# and add the registries fully-qualified name. +# +# Docker only +[registries.block] +registries = [{{ dockerengine_block_registries | wrap | join(',') }}] diff --git a/templates/etc/sysconfig/docker-storage-setup.j2 b/templates/etc/sysconfig/docker-storage-setup.j2 new file mode 100644 index 0000000..5a86f8c --- /dev/null +++ b/templates/etc/sysconfig/docker-storage-setup.j2 @@ -0,0 +1,7 @@ +# {{ ansible_managed }} +STORAGE_DRIVER=overlay2 +DEVS={{ dockerengine_storage_pvs }} +CONTAINER_ROOT_LV_NAME={{ dockerengine_storage_lv }} +CONTAINER_ROOT_LV_SIZE={{ dockerengine_storage_size }} +CONTAINER_ROOT_LV_MOUNT_PATH={{ dockerengine_base_dir }} +VG={{ dockerengine_storage_vg }} diff --git a/templates/etc/sysconfig/docker.j2 b/templates/etc/sysconfig/docker.j2 new file mode 100644 index 0000000..c0c1e43 --- /dev/null +++ b/templates/etc/sysconfig/docker.j2 @@ -0,0 +1,43 @@ +## {{ ansible_managed }} +# /etc/sysconfig/docker + +# Modify these options if you want to change the way the docker daemon runs +OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false' +if [ -z "${DOCKER_CERT_PATH}" ]; then + DOCKER_CERT_PATH=/etc/docker +fi + +# Do not add registries in this file anymore. Use /etc/containers/registries.conf +# from the atomic-registries package. +# + +# On an SELinux system, if you remove the --selinux-enabled option, you +# also need to turn on the docker_transition_unconfined boolean. +# setsebool -P docker_transition_unconfined 1 + +# Location used for temporary files, such as those created by +# docker load and build operations. Default is /var/lib/docker/tmp +# Can be overriden by setting the following environment variable. +# DOCKER_TMPDIR=/var/tmp + +# Controls the /etc/cron.daily/docker-logrotate cron job status. +# To disable, uncomment the line below. +# LOGROTATE=false + +# docker-latest daemon can be used by starting the docker-latest unitfile. +# To use docker-latest client, uncomment below lines +#DOCKERBINARY=/usr/bin/docker-latest +#DOCKERDBINARY=/usr/bin/dockerd-latest +#DOCKER_CONTAINERD_BINARY=/usr/bin/docker-containerd-latest +#DOCKER_CONTAINERD_SHIM_BINARY=/usr/bin/docker-containerd-shim-latest + +# Proxy settings +{% if dockerengine_http_proxy is defined %} +HTTP_PROXY={{ dockerengine_http_proxy }} +{% endif %} +{% if dockerengine_https_proxy is defined %} +HTTPS_PROXY={{ dockerengine_https_proxy }} +{% endif %} +{% if dockerengine_no_proxy is defined %} +NO_PROXY={{ dockerengine_no_proxy|join(',') }}" +{% endif %}