From 4ff845d56a955a8c6b9dd3088d72bbd651984fed Mon Sep 17 00:00:00 2001 From: Sven Velt Date: Thu, 19 Sep 2024 15:44:51 +0200 Subject: [PATCH] Kapitel 12: Cloud --- 12/db+wp.yml | 53 +++++++++++++++++++++++++++++++++++++++ 12/docker_install.yml | 12 +++++++++ 12/docker_install_old.yml | 50 ++++++++++++++++++++++++++++++++++++ 12/ping.yml | 7 ++++++ 12/setup.yml | 5 ++++ 5 files changed, 127 insertions(+) create mode 100644 12/db+wp.yml create mode 100644 12/docker_install.yml create mode 100644 12/docker_install_old.yml create mode 100644 12/ping.yml create mode 100644 12/setup.yml diff --git a/12/db+wp.yml b/12/db+wp.yml new file mode 100644 index 0000000..7e6a3a9 --- /dev/null +++ b/12/db+wp.yml @@ -0,0 +1,53 @@ +--- +- hosts: localhost + + vars: + my_image_mariadb: 'mariadb:10.3' + my_image_wordpress: 'wordpress' + + tasks: + - name: Download Docker image + docker_image: + name: '{{ item }}' + state: present + tag: latest + source: pull + with_items: + - '{{ my_image_mariadb }}' + - '{{ my_image_wordpress }}' + + - name: Create persistant volume (Ansible 2.4) + docker_volume: + name: db_data + state: present + + - name: Create DB container (Ansible 2.1) + docker_container: + name: db + image: '{{ my_image_mariadb }}' + volumes: + - db_data:/var/lib/mysql + restart_policy: always + env: + MYSQL_ROOT_PASSWORD: mysql + MYSQL_DATABASE: wordpress + MYSQL_USER: wordpress + MYSQL_PASSWORD: "{{ lookup('password', './wordpress.pw') }}" + + - name: Create WP container (Ansible 2.1) + docker_container: + name: wordpress + image: '{{ my_image_wordpress }}' + restart_policy: always + exposed_ports: + - 80 + published_ports: + - 8888:80 + links: + - db:db + env: + WORDPRESS_DB_HOST: db:3306 + WORDPRESS_DB_USER: wordpress + WORDPRESS_DB_PASSWORD: "{{ lookup('password', './wordpress.pw') }}" + + diff --git a/12/docker_install.yml b/12/docker_install.yml new file mode 100644 index 0000000..b0b9618 --- /dev/null +++ b/12/docker_install.yml @@ -0,0 +1,12 @@ +--- +- hosts: localhost + tasks: + - apt: + name: "{{ packages }}" + vars: + packages: + - docker.io + - docker-compose + - python3-docker + become: True + diff --git a/12/docker_install_old.yml b/12/docker_install_old.yml new file mode 100644 index 0000000..8b67c58 --- /dev/null +++ b/12/docker_install_old.yml @@ -0,0 +1,50 @@ +--- +- hosts: all + tasks: + - name: Update the apt package index + become: yes + apt: + name: "*" + state: latest + update_cache: yes + force_apt_get: yes + - name: Install packages for apt add repository over HTTPS + become: yes + apt: + 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 + - name: add docker official repository for Debian Stretch + apt_repository: + repo: deb [arch=amd64] https://download.docker.com/linux/debian stretch stable + state: present + - name: Index new repo into the cache + become: yes + apt: + name: "*" + state: latest + update_cache: yes + force_apt_get: yes + - name: actually install docker + apt: + name: "docker-ce" + state: latest +- name: Ensure docker-compose is installed and available + get_url: + url: https://github.com/docker/compose/releases/download/1.22.0/docker-compose-{{ ansible_system }}-{{ ansible_userspace_architecture }} + dest: /usr/local/bin/docker-compose + mode: 'u+x,g+x' diff --git a/12/ping.yml b/12/ping.yml new file mode 100644 index 0000000..acb5f2a --- /dev/null +++ b/12/ping.yml @@ -0,0 +1,7 @@ +--- +- hosts: + - all + - localhost + tasks: + - ping: + diff --git a/12/setup.yml b/12/setup.yml new file mode 100644 index 0000000..1f61bdd --- /dev/null +++ b/12/setup.yml @@ -0,0 +1,5 @@ +--- +- hosts: all + + tasks: [] +