From a3fba1094f0e558f3bd6989940fd7b6a1397f360 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Wed, 25 Nov 2020 16:46:20 +0100 Subject: [PATCH 1/4] Move phpmyadmin setup to distinct task list --- main.yml | 3 +++ tasks/docker_setup.yml | 16 +--------------- tasks/httpd.yml | 7 +------ tasks/phpmyadmin.yml | 23 +++++++++++++++++++++++ 4 files changed, 28 insertions(+), 21 deletions(-) create mode 100644 tasks/phpmyadmin.yml diff --git a/main.yml b/main.yml index 2b25a4e..0851bec 100644 --- a/main.yml +++ b/main.yml @@ -57,3 +57,6 @@ - name: Setup httpd include_tasks: tasks/httpd.yml + + - name: Setup phpmyadmin + include_tasks: tasks/phpmyadmin.yml diff --git a/tasks/docker_setup.yml b/tasks/docker_setup.yml index 59fdb63..3e05570 100644 --- a/tasks/docker_setup.yml +++ b/tasks/docker_setup.yml @@ -7,18 +7,4 @@ gateway: 192.168.0.1 state: present -- name: Setup phpmyadmin - docker_container: - name: phpmyadmin - state: started - image: phpmyadmin:5.0 - networks_cli_compatible: true - networks: - - name: dockernet - restart_policy: always - env: - PMA_HOST: 192.168.0.1 - MYSQL_ROOT_PASSWORD: "{{ mysql_root_pw }}" - PMA_ABSOLUTE_URI: "https://mysql.adm.netz39.de" - published_ports: - - 9001:80 + diff --git a/tasks/httpd.yml b/tasks/httpd.yml index 1f8ac4c..8e9aa27 100644 --- a/tasks/httpd.yml +++ b/tasks/httpd.yml @@ -10,12 +10,7 @@ name: rewrite state: present -- name: Setup proxy site mysql.adm.netz39.de - include_role: - name: setup-http-site-proxy - vars: - site_name: mysql.adm.netz39.de - proxy_port: 9001 + - name: Setup proxy site testredmine.netz39.de include_role: diff --git a/tasks/phpmyadmin.yml b/tasks/phpmyadmin.yml new file mode 100644 index 0000000..c9e0a09 --- /dev/null +++ b/tasks/phpmyadmin.yml @@ -0,0 +1,23 @@ +--- +- name: Setup phpmyadmin + docker_container: + name: phpmyadmin + state: started + image: phpmyadmin:5.0 + networks_cli_compatible: true + networks: + - name: dockernet + restart_policy: always + env: + PMA_HOST: 192.168.0.1 + MYSQL_ROOT_PASSWORD: "{{ mysql_root_pw }}" + PMA_ABSOLUTE_URI: "https://mysql.adm.netz39.de" + published_ports: + - 9001:80 + +- name: Setup proxy site mysql.adm.netz39.de + include_role: + name: setup-http-site-proxy + vars: + site_name: mysql.adm.netz39.de + proxy_port: 9001 From 1a50bbdfc72e54f92523d3ad37018a872aa69f1d Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Wed, 25 Nov 2020 16:55:50 +0100 Subject: [PATCH 2/4] Add docker installation as role --- roles/install-docker/handlers/main.yml | 6 ++ roles/install-docker/tasks/main.yml | 85 ++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 roles/install-docker/handlers/main.yml create mode 100644 roles/install-docker/tasks/main.yml diff --git a/roles/install-docker/handlers/main.yml b/roles/install-docker/handlers/main.yml new file mode 100644 index 0000000..4e8c5a0 --- /dev/null +++ b/roles/install-docker/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: restart docker + service: + name: docker + state: restarted + enabled: yes diff --git a/roles/install-docker/tasks/main.yml b/roles/install-docker/tasks/main.yml new file mode 100644 index 0000000..4590f0a --- /dev/null +++ b/roles/install-docker/tasks/main.yml @@ -0,0 +1,85 @@ +# This file is a mash-up of: +# https://github.com/geerlingguy/ansible-role-docker/blob/master/tasks/docker-compose.yml +# https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-debian-9 +# and our own stuff … +--- +- name: Gather package facts + package_facts: + manager: "auto" + +- name: Exit if docker.io is installed + fail: + msg: "Please remove docker.io (Debian vanilla docker package) first!" + when: "'docker.io' in ansible_facts.packages" + +- name: Install Docker APT deps + package: + name: "{{ packages }}" + state: present + vars: + packages: + - apt-transport-https + - ca-certificates + - gnupg2 + - software-properties-common + +- name: add Docker apt-key + apt_key: + url: https://download.docker.com/linux/debian/gpg + state: present + +- name: add Docker's APT repository + apt_repository: + repo: deb https://download.docker.com/linux/debian buster stable + state: present + update_cache: true + filename: 'docker' + +- name: install Docker + package: + name: "{{ packages }}" + state: present + vars: + packages: + - docker-ce + - python-docker + +- name: Set docker configuration + copy: + dest: /etc/docker/daemon.json + content: | + { + "exec-opts": ["native.cgroupdriver=systemd"], + "log-driver": "json-file", + "log-opts": { + "max-size": "100m" + } + } + notify: restart docker + +- 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 + +- name: Place admin users in docker group + user: + name: "{{ item }}" + groups: docker + append: yes + with_items: "{{ docker_users }}" From 5a18def5ed0e656cb00a1042182dc4baa9b809c2 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Wed, 25 Nov 2020 16:56:28 +0100 Subject: [PATCH 3/4] Use docker-install --- main.yml | 9 ++- tasks/{docker_setup.yml => docker_env.yml} | 0 tasks/docker_install.yml | 92 ---------------------- 3 files changed, 6 insertions(+), 95 deletions(-) rename tasks/{docker_setup.yml => docker_env.yml} (100%) delete mode 100644 tasks/docker_install.yml diff --git a/main.yml b/main.yml index 0851bec..008a3ad 100644 --- a/main.yml +++ b/main.yml @@ -50,10 +50,13 @@ include_tasks: tasks/users.yml - name: Install Docker - include_tasks: tasks/docker_install.yml + include_role: + name: install-docker + vars: + docker_users: "{{ admin_users }}" - - name: Setup Docker Containers - include_tasks: tasks/docker_setup.yml + - name: Setup Docker Environment + include_tasks: tasks/docker_env.yml - name: Setup httpd include_tasks: tasks/httpd.yml diff --git a/tasks/docker_setup.yml b/tasks/docker_env.yml similarity index 100% rename from tasks/docker_setup.yml rename to tasks/docker_env.yml diff --git a/tasks/docker_install.yml b/tasks/docker_install.yml deleted file mode 100644 index 38c91bf..0000000 --- a/tasks/docker_install.yml +++ /dev/null @@ -1,92 +0,0 @@ -# This file is a mash-up of: -# https://github.com/geerlingguy/ansible-role-docker/blob/master/tasks/docker-compose.yml -# https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-debian-9 -# and our own stuff … ---- -- name: Gather package facts - package_facts: - manager: "auto" - -- name: Exit if docker.io is installed - fail: - msg: "Please remove docker.io (Debian vanilla docker package) first!" - when: "'docker.io' in ansible_facts.packages" - -- name: Install Docker APT deps - package: - name: "{{ packages }}" - state: present - vars: - packages: - - apt-transport-https - - ca-certificates - - gnupg2 - - software-properties-common - -- name: add Docker apt-key - apt_key: - url: https://download.docker.com/linux/debian/gpg - state: present - -- name: add Docker's APT repository - apt_repository: - repo: deb https://download.docker.com/linux/debian buster stable - state: present - update_cache: true - filename: 'docker' - -- name: install Docker - package: - name: "{{ packages }}" - state: present - vars: - packages: - - docker-ce - - python-docker - -- name: Set docker configuration - copy: - dest: /etc/docker/daemon.json - content: | - { - "exec-opts": ["native.cgroupdriver=systemd"], - "log-driver": "json-file", - "log-opts": { - "max-size": "100m" - } - } - register: docker_config - -- name: Restart docker for changed configuration - service: - name: docker - state: restarted - enabled: yes - when: docker_config.changed - -- 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 - -- name: Place admin users in docker group - user: - name: "{{ item }}" - groups: docker - append: yes - with_items: "{{ admin_users }}" From 672ee65b2e1d8ef4ef6299ad3a19f6d0b6a5fb30 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Wed, 25 Nov 2020 17:02:34 +0100 Subject: [PATCH 4/4] Cleanup README --- README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e1cbfd3..5321d05 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,11 @@ Setup ```bash ansible-galaxy install -r requirements.yml -ansible-galaxy collection install community.general ``` Call with ```bash -ansible-playbook -i inventory httpd.yml +ansible-playbook -i inventory --ask-vault-pass main.yml ``` -You need to provide a user with sudo rights. +You need to provide a user with sudo rights and the vault password.