From d3e0654a57aa958aaef1906e4a759e521655a86b Mon Sep 17 00:00:00 2001 From: Peter Mikus <pmikus@cisco.com> Date: Wed, 16 Oct 2019 16:25:41 +0000 Subject: Ansible: Role cleanup + Separate and reuse role (better naming) + Cleanup in naming + Introduce defaults that can be overriden Signed-off-by: Peter Mikus <pmikus@cisco.com> Change-Id: Iedaf7caba1d05a35a6f61cd21a483cdbc0073d32 --- .../ansible/roles/docker/defaults/main.yaml | 27 +++++++++++ .../ansible/roles/docker/handlers/main.yaml | 8 ++++ .../ansible/roles/docker/tasks/main.yaml | 54 ++++++++++++++++++++++ .../ansible/roles/docker/tasks/ubuntu_bionic.yaml | 33 +++++++++++++ .../docker/templates/docker.service.proxy.http | 4 ++ .../docker/templates/docker.service.proxy.https | 4 ++ 6 files changed, 130 insertions(+) create mode 100644 resources/tools/testbed-setup/ansible/roles/docker/defaults/main.yaml create mode 100644 resources/tools/testbed-setup/ansible/roles/docker/handlers/main.yaml create mode 100644 resources/tools/testbed-setup/ansible/roles/docker/tasks/main.yaml create mode 100644 resources/tools/testbed-setup/ansible/roles/docker/tasks/ubuntu_bionic.yaml create mode 100644 resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.http create mode 100644 resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.https (limited to 'resources/tools/testbed-setup/ansible/roles/docker') diff --git a/resources/tools/testbed-setup/ansible/roles/docker/defaults/main.yaml b/resources/tools/testbed-setup/ansible/roles/docker/defaults/main.yaml new file mode 100644 index 0000000000..30958c9fa4 --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/docker/defaults/main.yaml @@ -0,0 +1,27 @@ +# Version options. +docker_edition: 'ce' +docker_version: '19.03.3' +docker_apt_package: '5:{{ docker_version }}~3-0~{{ ansible_distribution | lower }}-{{ ansible_distribution_release }}' +docker_apt_package_state: present + +# Service options. +docker_service_state: started +docker_service_enabled: true +docker_restart_handler_state: restarted + +# Used only for Debian/Ubuntu. Switch 'stable' to 'edge' if needed. +docker_apt_release_channel: 'edge' +docker_apt_repository: 'deb https://download.docker.com/linux/{{ ansible_distribution|lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}' +docker_apt_repository_state: present + +# A list of users who will be added to the docker group. +docker_users: + - 'testuser' + +# Proxy settings. +docker_daemon_environment_http: + - 'HTTP_PROXY={{ proxy_env.http_proxy }}' + - 'NO_PROXY={{ proxy_env.no_proxy }}' +docker_daemon_environment_https: + - 'HTTPS_PROXY={{ proxy_env.https_proxy }}' + - 'NO_PROXY={{ proxy_env.no_proxy }}' diff --git a/resources/tools/testbed-setup/ansible/roles/docker/handlers/main.yaml b/resources/tools/testbed-setup/ansible/roles/docker/handlers/main.yaml new file mode 100644 index 0000000000..d33c63fae8 --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/docker/handlers/main.yaml @@ -0,0 +1,8 @@ +--- +# file roles/docker/handlers/main.yaml + +- name: Restart Docker + service: + name: 'docker' + state: '{{ docker_restart_handler_state }}' + tags: restart-docker diff --git a/resources/tools/testbed-setup/ansible/roles/docker/tasks/main.yaml b/resources/tools/testbed-setup/ansible/roles/docker/tasks/main.yaml new file mode 100644 index 0000000000..368ddf5d1a --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/docker/tasks/main.yaml @@ -0,0 +1,54 @@ +--- +# file: roles/docker/tasks/main.yaml + +- name: Docker - Install distribution - release - machine prerequisites + include_tasks: '{{ ansible_distribution|lower }}_{{ ansible_distribution_release }}.yaml' + tags: install-docker + +- name: Docker - Create Service Directory + file: + path: '/etc/systemd/system/docker.service.d' + state: 'directory' + tags: install-docker + +- name: Docker - Setup HTTP Proxy + template: + src: 'templates/docker.service.proxy.http' + dest: '/etc/systemd/system/docker.service.d/http-proxy.conf' + owner: 'root' + group: 'root' + mode: '0644' + when: > + proxy_env is defined and + proxy_env.http_proxy is defined + tags: install-docker + +- name: Docker - Setup HTTPS Proxy + template: + src: 'templates/docker.service.proxy.https' + dest: '/etc/systemd/system/docker.service.d/https-proxy.conf' + owner: 'root' + group: 'root' + mode: '0644' + when: > + proxy_env is defined and + proxy_env.https_proxy is defined + tags: install-docker + +- name: Docker - Reload systemd daemon and restart service + command: 'systemctl daemon-reload' + notify: + - 'Restart Docker' + when: > + proxy_env is defined and + proxy_env.http_proxy is defined + tags: install-docker + +- name: Docker - Set specific users to docker group + user: + name: '{{ item }}' + groups: 'docker' + append: True + with_items: '{{ docker_users }}' + when: docker_users + tags: install-docker diff --git a/resources/tools/testbed-setup/ansible/roles/docker/tasks/ubuntu_bionic.yaml b/resources/tools/testbed-setup/ansible/roles/docker/tasks/ubuntu_bionic.yaml new file mode 100644 index 0000000000..32643b1119 --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/docker/tasks/ubuntu_bionic.yaml @@ -0,0 +1,33 @@ +--- +# file: roles/docker/tasks/ubuntu_bionic.yaml + +- name: Docker repository - Dependencies + apt: + name: + - 'apt-transport-https' + - 'ca-certificates' + - 'software-properties-common' + state: 'present' + cache_valid_time: 3600 + install_recommends: False + tags: install-docker + +- name: Docker repository - Add an Apt signing key + apt_key: + url: 'https://download.docker.com/linux/ubuntu/gpg' + state: 'present' + tags: install-docker + +- name: Docker repository - Install APT repository + apt_repository: + repo: '{{ docker_apt_repository }}' + state: '{{ docker_apt_repository_state }}' + update_cache: True + tags: install-docker + +- name: Install Docker + apt: + name: 'docker-{{ docker_edition }}={{ docker_apt_package }}' + state: '{{ docker_apt_package_state }}' + force: True + tags: install-docker diff --git a/resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.http b/resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.http new file mode 100644 index 0000000000..73ceba3870 --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.http @@ -0,0 +1,4 @@ +# {{ ansible_managed }} + +[Service] +Environment="{{ docker_daemon_environment_http | join('" "') }}" diff --git a/resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.https b/resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.https new file mode 100644 index 0000000000..1c2097eb9d --- /dev/null +++ b/resources/tools/testbed-setup/ansible/roles/docker/templates/docker.service.proxy.https @@ -0,0 +1,4 @@ +# {{ ansible_managed }} + +[Service] +Environment="{{ docker_daemon_environment_https | join('" "') }}" -- cgit 1.2.3-korg