diff --git a/.gitignore b/.gitignore index 1a507c5..ef96005 100644 --- a/.gitignore +++ b/.gitignore @@ -1,13 +1,8 @@ nodeAPI - +**/__pycache__/ # Created by https://www.gitignore.io/api/go,code,linux,macos,windows,eclipse,jetbrains # Edit at https://www.gitignore.io/?templates=go,code,linux,macos,windows,eclipse,jetbrains -### Build Artifacts & Generated Stuff ### -fenrir -deployment/e2e-k8s-job/*.yaml -venv - ### Code ### .vscode/* # !.vscode/settings.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c66a4c..4a466ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -* ansible playbook that provisions a cron-job that runs every midnight and should trigger aggregator -and routines +* ansible playbook that provisions a cron-job that runs every midnight and should trigger aggregator and routines +* ansible role to install docker and docker-compose [Unreleased]: https://github.com/maxisses/Covid-19API/compare/feature/add-aggregation-cron-job?expand=1 \ No newline at end of file diff --git a/ansible/README.md b/ansible/README.md index 0e1f063..d2dfdbb 100644 --- a/ansible/README.md +++ b/ansible/README.md @@ -8,7 +8,12 @@ In the command line run ```shell ansible-playbook playbook.yaml ``` -to get everything set up. +to get everything set up. That is: +* create a cron job +* install docker (if not installed) +* install python3 (if not installed) and necessary packages +* run the `flaskAPIwDocker` in a docker container +* Profit! ;) You can specify user, remote IP, host-key check, etc. optionally, like this: ```shell @@ -17,12 +22,44 @@ ansible-playbook \ --key-file ~/.ssh/.pem \ # provide SSH key --ssh-common-args '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' \ # skip host key checking -i \ # use different inventory file +-b \ # become -vvvv \ # very verbose playbook.yaml ``` +**Note**, that the setup is designed to run on an Ubuntu Linux with user `ubuntu` since ansible tasks +are using apt only (this may change in future versions). The provisioning can easily be adapted by +changing all fields with `CHANGE` mentions. + ## Test For testing, within the specific role, execute: ```shell -molecule converge # --debug optionally +molecule converge [--debug] +``` + +## Example Using AWS EC2 Instance +### Prerequisites +* AWS Account +* ansible is installed on your local system + +### Next Steps +* in the AWS console, create an EC2 instance with public IP and SSH keypair + * copy the private key and change permissions to "read only" (`400`) + * note the public IP of the EC2 instance +* modify the `./ansible/inventory` file to use your IP +* from local, run: +```shell script +ansible-playbook \ +-u ubuntu \ +--key-file .pem \ +--ssh-common-args '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null' \ +-i \ +-b \ +-vvvv \ +./ansible/playbook.yaml +``` +* wait a few minutes +After that, you can access the API via `:5000/`, e.g., +```shell script +curl 35.180.191.100:5000/get_total_cases ``` \ No newline at end of file diff --git a/ansible/inventory b/ansible/inventory index 55c65a9..0f601de 100644 --- a/ansible/inventory +++ b/ansible/inventory @@ -1,2 +1,4 @@ -[targets] -localhost ansible_connection=local \ No newline at end of file +[remote] +35.180.178.217 # CHANGE +[local] +localhost ansible_connection=local diff --git a/ansible/playbook.yaml b/ansible/playbook.yaml index 4970d28..9e1b814 100644 --- a/ansible/playbook.yaml +++ b/ansible/playbook.yaml @@ -1,6 +1,8 @@ --- - hosts: all - remote_user: user #TODO + remote_user: ubuntu # CHANGE become_user: root roles: - - role: cron-job \ No newline at end of file + - role: cron-job + - role: geerlingguy.docker + - role: flask-api diff --git a/ansible/roles/cron-job/tasks/main.yaml b/ansible/roles/cron-job/tasks/main.yaml index 8fabae6..bbcea83 100644 --- a/ansible/roles/cron-job/tasks/main.yaml +++ b/ansible/roles/cron-job/tasks/main.yaml @@ -4,7 +4,7 @@ src: ../../../../fillDatabase/aggregate.py dest: "{{ project_remote_dir }}" owner: ubuntu # CHANGE - mode: '0644' + mode: '0755' - name: Install cron become: yes @@ -18,4 +18,4 @@ name: "Aggregate case data" minute: 0 hour: 0 - job: "{{ aggregator_command }} > /dev/null 2>&1" \ No newline at end of file + job: "{{ aggregator_command }} > /dev/null 2>&1" diff --git a/ansible/roles/flask-api/defaults/main.yaml b/ansible/roles/flask-api/defaults/main.yaml new file mode 100644 index 0000000..83a5cb1 --- /dev/null +++ b/ansible/roles/flask-api/defaults/main.yaml @@ -0,0 +1,4 @@ +--- +project_remote_dir: /home/ubuntu # CHANGE +api_image_name: flaskapiwdocker_web_1 +postgres_image_name: flaskapiwdocker_postgresql_1 diff --git a/ansible/roles/flask-api/tasks/main.yaml b/ansible/roles/flask-api/tasks/main.yaml new file mode 100644 index 0000000..7d9d3dd --- /dev/null +++ b/ansible/roles/flask-api/tasks/main.yaml @@ -0,0 +1,56 @@ +--- +- name: Perform Pre-Installation Tasks + include_tasks: prerequisites.yaml + +- name: Tear down existing services + docker_compose: + project_src: "{{ project_remote_dir }}/flaskAPIwDocker" + state: absent + +- name: Create and start services + docker_compose: + project_src: flaskAPIwDocker + register: output + +- debug: + var: output + +- name: Run `docker-compose up` again + docker_compose: + project_src: "{{ project_remote_dir }}/flaskAPIwDocker" + build: no + register: output + +- debug: + var: output + +- assert: + that: "not output.changed " + +- name: Stop all services + docker_compose: + project_src: "{{ project_remote_dir }}/flaskAPIwDocker" + build: no + stopped: yes + register: output + +- debug: + var: output + +- assert: + that: + - "not web.{{ api_image_name }}.state.running" + +- name: Restart all services + docker_compose: + project_src: "{{ project_remote_dir }}/flaskAPIwDocker" + build: no + restarted: yes + register: output + +- debug: + var: output + +- assert: + that: + - "web.{{ api_image_name }}.state.running" diff --git a/ansible/roles/flask-api/tasks/prerequisites.yaml b/ansible/roles/flask-api/tasks/prerequisites.yaml new file mode 100644 index 0000000..a6ae477 --- /dev/null +++ b/ansible/roles/flask-api/tasks/prerequisites.yaml @@ -0,0 +1,21 @@ +--- +- name: Install Python plus utility packages + become: yes + apt: + name: + - python3-pip + - python3-virtualenv + - python3-dev + - virtualenv + - python3-docker + +- name: "Install Python3 docker compose" + pip: + name: docker-compose + +- name: "Copy API project directory to remote host's home" + copy: + src: ../../../../flaskAPIwDocker + dest: "{{ project_remote_dir }}" + owner: ubuntu # CHANGE + mode: '0644' diff --git a/ansible/roles/geerlingguy.docker/.ansible-lint b/ansible/roles/geerlingguy.docker/.ansible-lint new file mode 100644 index 0000000..4778564 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/.ansible-lint @@ -0,0 +1,2 @@ +skip_list: + - '306' diff --git a/ansible/roles/geerlingguy.docker/.github/FUNDING.yml b/ansible/roles/geerlingguy.docker/.github/FUNDING.yml new file mode 100644 index 0000000..96b4938 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/.github/FUNDING.yml @@ -0,0 +1,4 @@ +# These are supported funding model platforms +--- +github: geerlingguy +patreon: geerlingguy diff --git a/ansible/roles/geerlingguy.docker/.github/stale.yml b/ansible/roles/geerlingguy.docker/.github/stale.yml new file mode 100644 index 0000000..c7ff127 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/.github/stale.yml @@ -0,0 +1,56 @@ +# Configuration for probot-stale - https://github.com/probot/stale + +# Number of days of inactivity before an Issue or Pull Request becomes stale +daysUntilStale: 90 + +# Number of days of inactivity before an Issue or Pull Request with the stale label is closed. +# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. +daysUntilClose: 30 + +# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled) +onlyLabels: [] + +# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable +exemptLabels: + - pinned + - security + - planned + +# Set to true to ignore issues in a project (defaults to false) +exemptProjects: false + +# Set to true to ignore issues in a milestone (defaults to false) +exemptMilestones: false + +# Set to true to ignore issues with an assignee (defaults to false) +exemptAssignees: false + +# Label to use when marking as stale +staleLabel: stale + +# Limit the number of actions per hour, from 1-30. Default is 30 +limitPerRun: 30 + +pulls: + markComment: |- + This pull request has been marked 'stale' due to lack of recent activity. If there is no further activity, the PR will be closed in another 30 days. Thank you for your contribution! + + Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark pull requests as stale. + + unmarkComment: >- + This pull request is no longer marked for closure. + + closeComment: >- + This pull request has been closed due to inactivity. If you feel this is in error, please reopen the pull request or file a new PR with the relevant details. + +issues: + markComment: |- + This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! + + Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. + + unmarkComment: >- + This issue is no longer marked for closure. + + closeComment: >- + This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. diff --git a/ansible/roles/geerlingguy.docker/.gitignore b/ansible/roles/geerlingguy.docker/.gitignore new file mode 100644 index 0000000..f56f5b5 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/.gitignore @@ -0,0 +1,3 @@ +*.retry +*/__pycache__ +*.pyc diff --git a/ansible/roles/geerlingguy.docker/.travis.yml b/ansible/roles/geerlingguy.docker/.travis.yml new file mode 100644 index 0000000..a0001c3 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/.travis.yml @@ -0,0 +1,31 @@ +--- +language: python +services: docker + +env: + global: + - ROLE_NAME: docker + matrix: + - MOLECULE_DISTRO: centos8 + - MOLECULE_DISTRO: centos7 + - MOLECULE_DISTRO: ubuntu1804 + - MOLECULE_DISTRO: ubuntu1604 + - MOLECULE_DISTRO: debian10 + - MOLECULE_DISTRO: debian9 + +install: + # Install test dependencies. + - pip install molecule yamllint ansible-lint docker + +before_script: + # Use actual Ansible Galaxy role name for the project directory. + - cd ../ + - mv ansible-role-$ROLE_NAME geerlingguy.$ROLE_NAME + - cd geerlingguy.$ROLE_NAME + +script: + # Run tests. + - molecule test + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ diff --git a/ansible/roles/geerlingguy.docker/.yamllint b/ansible/roles/geerlingguy.docker/.yamllint new file mode 100644 index 0000000..7aeec5a --- /dev/null +++ b/ansible/roles/geerlingguy.docker/.yamllint @@ -0,0 +1,6 @@ +--- +extends: default +rules: + line-length: + max: 200 + level: warning diff --git a/ansible/roles/geerlingguy.docker/LICENSE b/ansible/roles/geerlingguy.docker/LICENSE new file mode 100644 index 0000000..4275cf3 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 Jeff Geerling + +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. diff --git a/ansible/roles/geerlingguy.docker/README.md b/ansible/roles/geerlingguy.docker/README.md new file mode 100644 index 0000000..036b560 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/README.md @@ -0,0 +1,97 @@ +# Ansible Role: Docker + +[![Build Status](https://travis-ci.org/geerlingguy/ansible-role-docker.svg?branch=master)](https://travis-ci.org/geerlingguy/ansible-role-docker) + +An Ansible Role that installs [Docker](https://www.docker.com) on Linux. + +## Requirements + +None. + +## Role Variables + +Available variables are listed below, along with default values (see `defaults/main.yml`): + + # Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition). + docker_edition: 'ce' + docker_package: "docker-{{ docker_edition }}" + docker_package_state: present + +The `docker_edition` should be either `ce` (Community Edition) or `ee` (Enterprise Edition). You can also specify a specific version of Docker to install using the distribution-specific format: Red Hat/CentOS: `docker-{{ docker_edition }}-`; Debian/Ubuntu: `docker-{{ docker_edition }}=`. + +You can control whether the package is installed, uninstalled, or at the latest version by setting `docker_package_state` to `present`, `absent`, or `latest`, respectively. Note that the Docker daemon will be automatically restarted if the Docker package is updated. This is a side effect of flushing all handlers (running any of the handlers that have been notified by this and any other role up to this point in the play). + + docker_service_state: started + docker_service_enabled: true + docker_restart_handler_state: restarted + +Variables to control the state of the `docker` service, and whether it should start on boot. If you're installing Docker inside a Docker container without systemd or sysvinit, you should set these to `stopped` and set the enabled variable to `no`. + + docker_install_compose: true + docker_compose_version: "1.25.4" + docker_compose_path: /usr/local/bin/docker-compose + +Docker Compose installation options. + + docker_apt_release_channel: stable + docker_apt_arch: amd64 + docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}" + docker_apt_ignore_key_error: True + docker_apt_gpg_key: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg + +(Used only for Debian/Ubuntu.) You can switch the channel to `edge` if you want to use the Edge release. + +You can change `docker_apt_gpg_key` to a different url if you are behind a firewall or provide a trustworthy mirror. +Usually in combination with changing `docker_apt_repository` as well. + + docker_yum_repo_url: https://download.docker.com/linux/centos/docker-{{ docker_edition }}.repo + docker_yum_repo_enable_edge: '0' + docker_yum_repo_enable_test: '0' + docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg + +(Used only for RedHat/CentOS.) You can enable the Edge or Test repo by setting the respective vars to `1`. + +You can change `docker_yum_gpg_key` to a different url if you are behind a firewall or provide a trustworthy mirror. +Usually in combination with changing `docker_yum_repository` as well. + + docker_users: + - user1 + - user2 + +A list of system users to be added to the `docker` group (so they can use Docker on the server). + +## Use with Ansible (and `docker` Python library) + +Many users of this role wish to also use Ansible to then _build_ Docker images and manage Docker containers on the server where Docker is installed. In this case, you can easily add in the `docker` Python library using the `geerlingguy.pip` role: + +```yaml +- hosts: all + + vars: + pip_install_packages: + - name: docker + + roles: + - geerlingguy.pip + - geerlingguy.docker +``` + +## Dependencies + +None. + +## Example Playbook + +```yaml +- hosts: all + roles: + - geerlingguy.docker +``` + +## License + +MIT / BSD + +## Author Information + +This role was created in 2017 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). diff --git a/ansible/roles/geerlingguy.docker/defaults/main.yml b/ansible/roles/geerlingguy.docker/defaults/main.yml new file mode 100644 index 0000000..ff05596 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/defaults/main.yml @@ -0,0 +1,33 @@ +--- +# Edition can be one of: 'ce' (Community Edition) or 'ee' (Enterprise Edition). +docker_edition: 'ce' +docker_package: "docker-{{ docker_edition }}" +docker_package_state: present + +# Service options. +docker_service_state: started +docker_service_enabled: true +docker_restart_handler_state: restarted + +# Docker Compose options. +docker_install_compose: true +docker_compose_version: "1.25.4" +docker_compose_path: /usr/local/bin/docker-compose + +# Used only for Debian/Ubuntu. Switch 'stable' to 'edge' if needed. +docker_apt_release_channel: stable +docker_apt_arch: amd64 +docker_apt_repository: "deb [arch={{ docker_apt_arch }}] https://download.docker.com/linux/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} {{ docker_apt_release_channel }}" +docker_apt_ignore_key_error: true +docker_apt_gpg_key: https://download.docker.com/linux/{{ ansible_distribution | lower }}/gpg + +# Used only for RedHat/CentOS/Fedora. +docker_yum_repo_url: https://download.docker.com/linux/{{ (ansible_distribution == "Fedora") | ternary("fedora","centos") }}/docker-{{ docker_edition }}.repo +docker_yum_repo_enable_edge: '0' +docker_yum_repo_enable_test: '0' +docker_yum_gpg_key: https://download.docker.com/linux/centos/gpg + +# A list of users who will be added to the docker group. +docker_users: + - root + - ubuntu # CHANGE diff --git a/ansible/roles/geerlingguy.docker/handlers/main.yml b/ansible/roles/geerlingguy.docker/handlers/main.yml new file mode 100644 index 0000000..7847bc1 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/handlers/main.yml @@ -0,0 +1,3 @@ +--- +- name: restart docker + service: "name=docker state={{ docker_restart_handler_state }}" diff --git a/ansible/roles/geerlingguy.docker/meta/.galaxy_install_info b/ansible/roles/geerlingguy.docker/meta/.galaxy_install_info new file mode 100644 index 0000000..4c620cb --- /dev/null +++ b/ansible/roles/geerlingguy.docker/meta/.galaxy_install_info @@ -0,0 +1,2 @@ +install_date: Sat Mar 21 13:31:28 2020 +version: 2.7.0 diff --git a/ansible/roles/geerlingguy.docker/meta/main.yml b/ansible/roles/geerlingguy.docker/meta/main.yml new file mode 100644 index 0000000..82065cd --- /dev/null +++ b/ansible/roles/geerlingguy.docker/meta/main.yml @@ -0,0 +1,33 @@ +--- +dependencies: [] + +galaxy_info: + author: geerlingguy + description: Docker for Linux. + company: "Midwestern Mac, LLC" + license: "license (BSD, MIT)" + min_ansible_version: 2.4 + platforms: + - name: EL + versions: + - 7 + - 8 + - name: Fedora + versions: + - all + - name: Debian + versions: + - stretch + - buster + - name: Ubuntu + versions: + - xenial + - bionic + galaxy_tags: + - web + - system + - containers + - docker + - orchestration + - compose + - server diff --git a/ansible/roles/geerlingguy.docker/molecule/default/converge.yml b/ansible/roles/geerlingguy.docker/molecule/default/converge.yml new file mode 100644 index 0000000..dad331d --- /dev/null +++ b/ansible/roles/geerlingguy.docker/molecule/default/converge.yml @@ -0,0 +1,12 @@ +--- +- name: Converge + hosts: all + become: true + + pre_tasks: + - name: Update apt cache. + apt: update_cache=yes cache_valid_time=600 + when: ansible_os_family == 'Debian' + + roles: + - role: geerlingguy.docker diff --git a/ansible/roles/geerlingguy.docker/molecule/default/molecule.yml b/ansible/roles/geerlingguy.docker/molecule/default/molecule.yml new file mode 100644 index 0000000..2da47dd --- /dev/null +++ b/ansible/roles/geerlingguy.docker/molecule/default/molecule.yml @@ -0,0 +1,21 @@ +--- +dependency: + name: galaxy +driver: + name: docker +lint: | + set -e + yamllint . + ansible-lint +platforms: + - name: instance + image: "geerlingguy/docker-${MOLECULE_DISTRO:-centos7}-ansible:latest" + command: ${MOLECULE_DOCKER_COMMAND:-""} + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro + privileged: true + pre_build_image: true +provisioner: + name: ansible + playbooks: + converge: ${MOLECULE_PLAYBOOK:-converge.yml} diff --git a/ansible/roles/geerlingguy.docker/tasks/docker-compose.yml b/ansible/roles/geerlingguy.docker/tasks/docker-compose.yml new file mode 100644 index 0000000..92cf4f2 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/tasks/docker-compose.yml @@ -0,0 +1,20 @@ +--- +- name: Check current docker-compose version. + command: docker-compose --version + register: docker_compose_current_version + changed_when: false + failed_when: false + +- name: Delete existing docker-compose version if it's different. + file: + path: "{{ docker_compose_path }}" + state: absent + when: > + docker_compose_current_version.stdout is defined + and docker_compose_version not in docker_compose_current_version.stdout + +- name: Install Docker Compose (if configured). + get_url: + url: https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-x86_64 + dest: "{{ docker_compose_path }}" + mode: 0755 diff --git a/ansible/roles/geerlingguy.docker/tasks/docker-users.yml b/ansible/roles/geerlingguy.docker/tasks/docker-users.yml new file mode 100644 index 0000000..b3b6e0f --- /dev/null +++ b/ansible/roles/geerlingguy.docker/tasks/docker-users.yml @@ -0,0 +1,7 @@ +--- +- name: Ensure docker users are added to the docker group. + user: + name: "{{ item }}" + groups: docker + append: true + with_items: "{{ docker_users }}" diff --git a/ansible/roles/geerlingguy.docker/tasks/main.yml b/ansible/roles/geerlingguy.docker/tasks/main.yml new file mode 100644 index 0000000..56449ef --- /dev/null +++ b/ansible/roles/geerlingguy.docker/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- include_tasks: setup-RedHat.yml + when: ansible_os_family == 'RedHat' + +- include_tasks: setup-Debian.yml + when: ansible_os_family == 'Debian' + +- name: Install Docker. + package: + name: "{{ docker_package }}" + state: "{{ docker_package_state }}" + notify: restart docker + +- name: Ensure Docker is started and enabled at boot. + service: + name: docker + state: "{{ docker_service_state }}" + enabled: "{{ docker_service_enabled }}" + +- name: Ensure handlers are notified now to avoid firewall conflicts. + meta: flush_handlers + +- include_tasks: docker-compose.yml + when: docker_install_compose | bool + +- include_tasks: docker-users.yml + when: docker_users | length > 0 diff --git a/ansible/roles/geerlingguy.docker/tasks/setup-Debian.yml b/ansible/roles/geerlingguy.docker/tasks/setup-Debian.yml new file mode 100644 index 0000000..d701135 --- /dev/null +++ b/ansible/roles/geerlingguy.docker/tasks/setup-Debian.yml @@ -0,0 +1,40 @@ +--- +- name: Ensure old versions of Docker are not installed. + package: + name: + - docker + - docker-engine + state: absent + +- name: Ensure dependencies are installed. + apt: + name: + - apt-transport-https + - ca-certificates + - gnupg2 + state: present + +- name: Add Docker apt key. + apt_key: + url: "{{ docker_apt_gpg_key }}" + id: 9DC858229FC7DD38854AE2D88D81803C0EBFCD88 + state: present + register: add_repository_key + ignore_errors: "{{ docker_apt_ignore_key_error }}" + +- name: Ensure curl is present (on older systems without SNI). + package: name=curl state=present + when: add_repository_key is failed + +- name: Add Docker apt key (alternative for older systems without SNI). + shell: > + curl -sSL {{ docker_apt_gpg_key }} | sudo apt-key add - + args: + warn: false + when: add_repository_key is failed + +- name: Add Docker repository. + apt_repository: + repo: "{{ docker_apt_repository }}" + state: present + update_cache: true diff --git a/ansible/roles/geerlingguy.docker/tasks/setup-RedHat.yml b/ansible/roles/geerlingguy.docker/tasks/setup-RedHat.yml new file mode 100644 index 0000000..800c0bc --- /dev/null +++ b/ansible/roles/geerlingguy.docker/tasks/setup-RedHat.yml @@ -0,0 +1,41 @@ +--- +- name: Ensure old versions of Docker are not installed. + package: + name: + - docker + - docker-common + - docker-engine + state: absent + +- name: Add Docker GPG key. + rpm_key: + key: "{{ docker_yum_gpg_key }}" + state: present + +- name: Add Docker repository. + get_url: + url: "{{ docker_yum_repo_url }}" + dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo' + owner: root + group: root + mode: 0644 + +- name: Configure Docker Edge repo. + ini_file: + dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo' + section: 'docker-{{ docker_edition }}-edge' + option: enabled + value: '{{ docker_yum_repo_enable_edge }}' + +- name: Configure Docker Test repo. + ini_file: + dest: '/etc/yum.repos.d/docker-{{ docker_edition }}.repo' + section: 'docker-{{ docker_edition }}-test' + option: enabled + value: '{{ docker_yum_repo_enable_test }}' + +- name: Install containerd separately (CentOS 8). + package: + name: https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.6-3.3.el7.x86_64.rpm + state: present + when: ansible_distribution_major_version | int == 8 diff --git a/flaskAPIwDocker/hello/__pycache__/__init__.cpython-36.pyc b/flaskAPIwDocker/hello/__pycache__/__init__.cpython-36.pyc deleted file mode 100644 index c8add61..0000000 Binary files a/flaskAPIwDocker/hello/__pycache__/__init__.cpython-36.pyc and /dev/null differ diff --git a/flaskAPIwDocker/hello/__pycache__/app.cpython-36.pyc b/flaskAPIwDocker/hello/__pycache__/app.cpython-36.pyc deleted file mode 100644 index 6405e8d..0000000 Binary files a/flaskAPIwDocker/hello/__pycache__/app.cpython-36.pyc and /dev/null differ