Kapitel 12: Cloud

This commit is contained in:
Sven Velt 2024-09-19 15:44:51 +02:00
parent 83d9994719
commit 4ff845d56a
5 changed files with 127 additions and 0 deletions

53
12/db+wp.yml Normal file
View file

@ -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') }}"

12
12/docker_install.yml Normal file
View file

@ -0,0 +1,12 @@
---
- hosts: localhost
tasks:
- apt:
name: "{{ packages }}"
vars:
packages:
- docker.io
- docker-compose
- python3-docker
become: True

50
12/docker_install_old.yml Normal file
View file

@ -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'

7
12/ping.yml Normal file
View file

@ -0,0 +1,7 @@
---
- hosts:
- all
- localhost
tasks:
- ping:

5
12/setup.yml Normal file
View file

@ -0,0 +1,5 @@
---
- hosts: all
tasks: []