diff --git a/playbooks/setup_docker.yml b/playbooks/setup_docker.yml new file mode 100644 index 0000000..c6ac8c2 --- /dev/null +++ b/playbooks/setup_docker.yml @@ -0,0 +1,7 @@ +--- +- name: setup Docker + hosts: vps + remote_user: root + roles: + - docker_host +... diff --git a/roles/docker_host/README.md b/roles/docker_host/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/roles/docker_host/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/docker_host/defaults/main.yml b/roles/docker_host/defaults/main.yml new file mode 100644 index 0000000..e11b17c --- /dev/null +++ b/roles/docker_host/defaults/main.yml @@ -0,0 +1,7 @@ +--- +# defaults file for docker +docker_https_proxy_url: "{{ mmw_proxy|default('') }}" +docker_http_proxy_url: "{{ mmw_proxy|default('') }}" +docker_no_proxy_url: "localhost,127.0.0.1,172.16.0.0/16,10.100.0.0/16,.{{ ansible_domain }}" +docker_compose_version: "1.27.4" + diff --git a/roles/docker_host/files/docker-ce.gpg b/roles/docker_host/files/docker-ce.gpg new file mode 100644 index 0000000..1967cbf --- /dev/null +++ b/roles/docker_host/files/docker-ce.gpg @@ -0,0 +1,28 @@ +-----BEGIN PGP PUBLIC KEY BLOCK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fqDN1uoKMlV+WFuB1j2oTUuO1/dr8mL+FgZAM3 +ntWFo9gQCllNV9ahYOON2gkoZoNuPUnHsf4Bj6BQJnIXbAhMk9H2sZzwUi9bgObZ +XO8+OrP4D4B9kCAKqqaQqA+O46LzO2vhN74lm/Fy6PumHuviqDBdN+HgtRPMUuao +xnuVJSvBu9sPdgT/pR1N9u/KnfAnnLtR6g+fx4mWz+ts/riB/KRHzXd+44jGKZra +IhTMfniguMJNsyEOO0AN8Tqcl0eRBxcOArcri7xu8HFvvl+e+ILymu4buusbYEVL +GBkYP5YMmScfKn+jnDVN4mWoN1Bq2yMhMGx6PA3hOvzPNsUoYy2BwDxNZyflzuAi +g59mgJm2NXtzNbSRJbMamKpQ69mzLWGdFNsRd4aH7PT7uPAURaf7B5BVp3UyjERW +5alSGnBqsZmvlRnVH5BDUhYsWZMPRQS9rRr4iGW0l+TH+O2VJ8aQ +=0Zqq +-----END PGP PUBLIC KEY BLOCK----- diff --git a/roles/docker_host/files/docker-ce.repo b/roles/docker_host/files/docker-ce.repo new file mode 100644 index 0000000..1abdbe3 --- /dev/null +++ b/roles/docker_host/files/docker-ce.repo @@ -0,0 +1,62 @@ +[docker-ce-stable] +name=Docker CE Stable - $basearch +baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/stable +enabled=1 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-stable-debuginfo] +name=Docker CE Stable - Debuginfo $basearch +baseurl=https://download.docker.com/linux/centos/$releasever/debug-$basearch/stable +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-stable-source] +name=Docker CE Stable - Sources +baseurl=https://download.docker.com/linux/centos/$releasever/source/stable +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-test] +name=Docker CE Test - $basearch +baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/test +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-test-debuginfo] +name=Docker CE Test - Debuginfo $basearch +baseurl=https://download.docker.com/linux/centos/$releasever/debug-$basearch/test +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-test-source] +name=Docker CE Test - Sources +baseurl=https://download.docker.com/linux/centos/$releasever/source/test +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-nightly] +name=Docker CE Nightly - $basearch +baseurl=https://download.docker.com/linux/centos/$releasever/$basearch/nightly +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-nightly-debuginfo] +name=Docker CE Nightly - Debuginfo $basearch +baseurl=https://download.docker.com/linux/centos/$releasever/debug-$basearch/nightly +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg + +[docker-ce-nightly-source] +name=Docker CE Nightly - Sources +baseurl=https://download.docker.com/linux/centos/$releasever/source/nightly +enabled=0 +gpgcheck=1 +gpgkey=https://download.docker.com/linux/centos/gpg diff --git a/roles/docker_host/handlers/main.yml b/roles/docker_host/handlers/main.yml new file mode 100644 index 0000000..9164066 --- /dev/null +++ b/roles/docker_host/handlers/main.yml @@ -0,0 +1,8 @@ +--- +# handlers file for docker +- name: restart docker + systemd: + name: docker + daemon_reload: yes + state: restarted +... diff --git a/roles/docker_host/meta/main.yml b/roles/docker_host/meta/main.yml new file mode 100644 index 0000000..4f793d0 --- /dev/null +++ b/roles/docker_host/meta/main.yml @@ -0,0 +1,49 @@ +galaxy_info: + author: D. Boggasch / J. Heinitz + description: Role to install all packages to run docker + company: M.M.Warburg & CO KG + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: GPL-2.0-or-later + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + platforms: + - name: Debian + versions: + - all + - name: RedHat + versions: + - all + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. +... diff --git a/roles/docker_host/tasks/CentOS.yml b/roles/docker_host/tasks/CentOS.yml new file mode 100644 index 0000000..1e9559f --- /dev/null +++ b/roles/docker_host/tasks/CentOS.yml @@ -0,0 +1,26 @@ +- name: Copy Docker GPG Public Key. + copy: + src: "docker-ce.gpg" + dest: '/etc/yum.repos.d/docker-ce.gpg' + owner: root + group: root + mode: 0644 + +- name: Add Docker GPG key. + rpm_key: + key: "/etc/yum.repos.d/docker-ce.gpg" + state: present + when: ansible_distribution == "RedHat" + +- name: Add Docker repository. + copy: + src: "docker-ce.repo" + dest: '/etc/yum.repos.d/docker-ce.repo' + owner: root + group: root + mode: 0644 + +- name: Install python-selinux + yum: + state: present + name: "libselinux-python3" \ No newline at end of file diff --git a/roles/docker_host/tasks/Debian.yml b/roles/docker_host/tasks/Debian.yml new file mode 100644 index 0000000..1f1a6bd --- /dev/null +++ b/roles/docker_host/tasks/Debian.yml @@ -0,0 +1,44 @@ +- name: Update the apt package index + apt: # noqa 403 - we want to upgrade all packages to latest + name: "*" + state: latest + update_cache: yes + force_apt_get: yes +- name: Install packages for apt add repository over HTTPS + apt: # noqa 403 - we want to upgrade all packages to latest + name: "{{ packagesdep }}" + force_apt_get: yes + state: latest + update_cache: yes + vars: + packagesdep: + - git + - apt-transport-https + - ca-certificates + - wget + - software-properties-common + - gnupg2 + - curl +- name: Add Apt signing key from official docker repo + apt_key: + url: https://download.docker.com/linux/debian/gpg + state: present + environment: + http_proxy: "{{ mmw_proxy|default('') }}" + https_proxy: "{{ mmw_proxy|default('') }}" +- name: add docker official repository for Debian Stretch + apt_repository: + repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable" + state: present +- name: Index new repo into the cache + apt: # noqa 403 - we want to upgrade all packages to latest + name: "*" + state: latest + update_cache: yes + force_apt_get: yes + +- name: Install python-selinux + apt: + state: present + name: "python3-selinux" +... diff --git a/roles/docker_host/tasks/RedHat.yml b/roles/docker_host/tasks/RedHat.yml new file mode 100644 index 0000000..2e09e15 --- /dev/null +++ b/roles/docker_host/tasks/RedHat.yml @@ -0,0 +1,6 @@ +--- +- name: Install python-selinux + yum: + state: present + name: "libselinux-python3" +... \ No newline at end of file diff --git a/roles/docker_host/tasks/Ubuntu.yml b/roles/docker_host/tasks/Ubuntu.yml new file mode 100644 index 0000000..f20dd96 --- /dev/null +++ b/roles/docker_host/tasks/Ubuntu.yml @@ -0,0 +1,44 @@ +- name: Update the apt package index + apt: # noqa 403 - we want to update all packages to latest + name: "*" + state: latest + update_cache: yes + force_apt_get: yes +- name: Install packages for apt add repository over HTTPS + apt: # noqa 403 - we want to update all packages to latest + name: "{{ packagesdep }}" + force_apt_get: yes + state: latest + update_cache: yes + vars: + packagesdep: + - git + - apt-transport-https + - ca-certificates + - wget + - software-properties-common + - gnupg2 + - curl +- name: Add Apt signing key from official docker repo + apt_key: + url: https://download.docker.com/linux/ubuntu/gpg + state: present + environment: + http_proxy: "{{ mmw_proxy }}" + https_proxy: "{{ mmw_proxy }}" +- name: add docker official repository for Ubuntu + apt_repository: + repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" + state: present +- name: Index new repo into the cache + apt: # noqa 403 - we want to update all packages to latest + name: "*" + state: latest + update_cache: yes + force_apt_get: yes + +- name: Install python-selinux + apt: + state: present + name: "python3-selinux" +... diff --git a/roles/docker_host/tasks/main.yml b/roles/docker_host/tasks/main.yml new file mode 100644 index 0000000..fc9298c --- /dev/null +++ b/roles/docker_host/tasks/main.yml @@ -0,0 +1,82 @@ +--- +# tasks file for docker +- name: Ensure old versions of Docker are not installed. + package: + name: + - docker + - docker-common + - docker-engine + state: absent + +- name: setup Debian system + include_tasks: Debian.yml + when: ansible_distribution == "Debian" + +- name: setup RedHat system + include_tasks: CentOS.yml + when: ansible_distribution == "CentOS" + +- name: setup Ubuntu system + include_tasks: Ubuntu.yml + when: ansible_distribution == 'Ubuntu' + +- name: setup RedHat system + include_tasks: RedHat.yml + when: ansible_distribution == 'RedHat' + +- name: Install Docker and containerd. + package: + name: "{{ item }}" + state: present + with_items: + - docker-ce + - docker-ce-cli + - containerd.io + - python3-pip + +- name: Create systemd docker.service.d. + file: + path: '/etc/systemd/system/docker.service.d' + state: directory + owner: root + group: root + mode: '0644' + notify: restart docker + +- name: Template Proxy Settings for Docker Daemon. + template: + src: 'docker-proxy.conf' + dest: '/etc/systemd/system/docker.service.d/docker-proxy.conf' + owner: root + group: root + mode: '0644' + +- name: Ensure Docker is started and enabled at boot. + service: + name: docker + state: started + enabled: true + +- name: Ensure handlers are notified now to avoid firewall conflicts. + meta: flush_handlers + +- name: install docker / docker-compose sdk + pip: + name: + - docker + - docker-compose + vars: + ansible_python_interpreter: /usr/bin/python3 + environment: + http_proxy: "{{ mmw_proxy|default('') }}" + https_proxy: "{{ mmw_proxy|default('') }}" + + +- name: install docker-compose + get_url: + dest: /usr/local/bin/docker-compose + url: "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64" + mode: '0755' + environment: + https_proxy: "{{ mmw_proxy|default('') }}" +... diff --git a/roles/docker_host/templates/docker-proxy.conf b/roles/docker_host/templates/docker-proxy.conf new file mode 100644 index 0000000..7400b4d --- /dev/null +++ b/roles/docker_host/templates/docker-proxy.conf @@ -0,0 +1,2 @@ +[Service] +Environment="HTTPS_PROXY={{ docker_https_proxy_url }}" "HTTP_PROXY={{ docker_http_proxy_url }}" "NO_PROXY={{ docker_no_proxy_url }}" diff --git a/roles/docker_host/tests/inventory b/roles/docker_host/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/roles/docker_host/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/roles/docker_host/tests/test.yml b/roles/docker_host/tests/test.yml new file mode 100644 index 0000000..2c81ca4 --- /dev/null +++ b/roles/docker_host/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - docker \ No newline at end of file diff --git a/roles/docker_host/vars/main.yml b/roles/docker_host/vars/main.yml new file mode 100644 index 0000000..dc934ce --- /dev/null +++ b/roles/docker_host/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for docker \ No newline at end of file