Skip to content

Commit 3b05d95

Browse files
author
abregman
committed
Add 57 new questions and exercises
1 parent 6e01886 commit 3b05d95

27 files changed

+1973
-234
lines changed

README.md

+758-234
Large diffs are not rendered by default.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Ansible - My First Playbook
2+
3+
1. Write a playbook that will:
4+
a. Install the package zlib
5+
b. Create the file `/tmp/some_file`
6+
2. Run the playbook on a remote host

exercises/ansible/my_first_task.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## Ansible - My First Task
2+
3+
1. Write a task to create the directory ‘/tmp/new_directory’
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## My first playbook - Solution
2+
3+
1. `vi first_playbook.yml`
4+
5+
```
6+
- name: Install zlib and create a file
7+
hosts: some_remote_host
8+
tasks:
9+
- name: Install zlib
10+
package:
11+
name: zlib
12+
state: present
13+
become: yes
14+
- name: Create the file /tmp/some_file
15+
path: '/tmp/some_file'
16+
state: touch
17+
```
18+
19+
2. First, edit the inventory file: `vi /etc/ansible/hosts`
20+
21+
```
22+
[some_remote_host]
23+
some.remoted.host.com
24+
```
25+
26+
Run the playbook
27+
28+
`ansible-playbook first_playbook.yml`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## My First Task - Solution
2+
3+
```
4+
- name: Create a new directory
5+
file:
6+
path: "/tmp/new_directory"
7+
state: directory
8+
```
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Deploy to Kubernetes
2+
3+
* Write a pipeline that will deploy an "hello world" web app to Kubernete
4+
* The CI/CD system (where the pipeline resides) and the Kubernetes cluster should be on separate systems
5+
* The web app should be accessible remotely and only with HTTPS
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
pipeline {
2+
3+
agent any
4+
5+
stages {
6+
7+
stage('Checkout Source') {
8+
steps {
9+
git url:'https://github.com/<GITHUB_USERNAME>/<YOUR_WEB_APP_REPO>.git',
10+
// credentialsId: 'creds_github',
11+
branch:'master'
12+
}
13+
}
14+
15+
stage("Build image") {
16+
steps {
17+
script {
18+
myapp = docker.build("<YOUR_DOCKER_USERNAME>/helloworld:${env.BUILD_ID}")
19+
}
20+
}
21+
}
22+
23+
stage("Push image") {
24+
steps {
25+
script {
26+
docker.withRegistry('https://registry.hub.docker.com', 'dockerhub') {
27+
myapp.push("latest")
28+
myapp.push("${env.BUILD_ID}")
29+
}
30+
}
31+
}
32+
}
33+
34+
35+
stage('Deploy App') {
36+
steps {
37+
script {
38+
sh 'ansible-playbook deploy.yml'
39+
}
40+
}
41+
}
42+
43+
}
44+
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Deploy to Kubernetes
2+
3+
Note: this exercise can be solved in various ways. The solution described here is just one possible way.
4+
5+
1. Install Jenkins on one system (follow up the standard Jenkins installation procedure)
6+
2. Deploy Kubernetes on a remote host (minikube can be an easy way to achieve it)
7+
3. Create a simple web app or [page](html)
8+
9+
4. Create Kubernetes [resoruces](helloworld.yml) - Deployment, Service and Ingress (for HTTPS access)
10+
5. Create an [Ansible inventory](inventory) and insert the address of the Kubernetes cluster
11+
6. Write [Ansible playbook](deploy.yml) to deploy the Kubernetes resources and also generate
12+
7. Create a [pipeline](Jenkinsfile)
13+
14+
8. Run the pipeline :)
15+
9. Try to access the web app remotely
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
- name: Apply Kubernetes YAMLs
2+
hosts: kubernetes
3+
tasks:
4+
- name: Ensure SSL related directories exist
5+
file:
6+
path: "{{ item }}"
7+
state: directory
8+
loop:
9+
- "/etc/ssl/crt"
10+
- "/etc/ssl/csr"
11+
- "/etc/ssl/private"
12+
13+
- name: Generate an OpenSSL private key.
14+
openssl_privatekey:
15+
path: /etc/ssl/private/privkey.pem
16+
17+
- name: generate openssl certficate signing requests
18+
openssl_csr:
19+
path: /etc/ssl/csr/hello-world.app.csr
20+
privatekey_path: /etc/ssl/private/privkey.pem
21+
common_name: hello-world.app
22+
23+
- name: Generate a Self Signed OpenSSL certificate
24+
openssl_certificate:
25+
path: /etc/ssl/crt/hello-world.app.crt
26+
privatekey_path: /etc/ssl/private/privkey.pem
27+
csr_path: /etc/ssl/csr/hello-world.app.csr
28+
provider: selfsigned
29+
30+
- name: Create k8s secret
31+
command: "kubectl create secret tls tls-secret --cert=/etc/ssl/crt/hello-world.app.crt --key=/etc/ssl/private/privkey.pem"
32+
register: result
33+
failed_when:
34+
- result.rc == 2
35+
36+
- name: Deploy web app
37+
k8s:
38+
state: present
39+
definition: "{{ lookup('file', './helloworld.yml') }}"
40+
kubeconfig: '/home/abregman/.kube/config'
41+
namespace: 'default'
42+
wait: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
apiVersion: apps/v1
3+
kind: Deployment
4+
metadata:
5+
name: hello-blue-whale
6+
spec:
7+
replicas: 3
8+
selector:
9+
matchLabels:
10+
app: hello-world-app
11+
version: blue
12+
template:
13+
metadata:
14+
name: hello-blue-whale-pod
15+
labels:
16+
app: hello-world-app
17+
version: blue
18+
spec:
19+
containers:
20+
- name: hello-whale-container
21+
image: abregman2/helloworld:latest
22+
imagePullPolicy: Always
23+
ports:
24+
- containerPort: 80
25+
- containerPort: 443
26+
---
27+
apiVersion: v1
28+
kind: Service
29+
metadata:
30+
name: hello-world
31+
labels:
32+
app: hello-world-app
33+
spec:
34+
ports:
35+
- port: 80
36+
targetPort: 80
37+
protocol: TCP
38+
name: http
39+
selector:
40+
app: hello-world-app
41+
---
42+
apiVersion: networking.k8s.io/v1
43+
kind: Ingress
44+
metadata:
45+
name: example-ingress
46+
annotations:
47+
cert-manager.io/cluster-issuer: selfsigned-issuer
48+
nginx.ingress.kubernetes.io/rewrite-target: /
49+
kubernetes.io/ingress.class: nginx
50+
spec:
51+
tls:
52+
- hosts:
53+
- hello-world.app
54+
secretName: shhh
55+
rules:
56+
- host: hello-world.app
57+
http:
58+
paths:
59+
- path: /
60+
pathType: Prefix
61+
backend:
62+
service:
63+
name: hello-world
64+
port:
65+
number: 80

0 commit comments

Comments
 (0)