Skip to content

Commit b91e922

Browse files
committed
Ansible homework
1 parent 63b2492 commit b91e922

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

M1-3-Ansible/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# M1-3-1 Configuration Management
2+
3+
## Ansible Task
4+
5+
Create an Ansible playbook that build, push and then run the Docker image for the Python
6+
application. Let your playbook has the following variables:
7+
8+
* `image_name` - contains the name of your image without the tag, i.e. `vutoff/python-app`
9+
* `image_tag` - contains the tag you tagged your image with, i.e. `v0.2`
10+
* `listen_port` - contains the listening port you're binding your app to.
11+
12+
Make sure that you set environment variable `PORT` when you define your container
13+
in the Ansible playbook that takes its value from `listen_port` variable.
14+
15+
Use Ansible modules. Do not shell out.
16+
17+
### Requirements
18+
19+
* Make sure you have Python installed. Any version above 3.8 would suffice.
20+
* The `requirements.txt` file in this directory contains the required Ansible version. Run
21+
22+
```sh
23+
pip install -r requirements.txt
24+
```
25+
26+
* Make sure that Docker is running on your local machine.
27+
28+
### Mind the following
29+
30+
* If you're running Docker Desktop or Rancher Desktop, mind the location of the `docker.sock` file. The location of the socket file is
31+
* Docker Desktop - `${HOME}/.docker/run/docker.sock`
32+
* Rancher DEsktop - ${HOME}/.rd/run/docker.sock
33+
34+
* If you're using one of the above, when you write your Ansible playbook you
35+
must specify the path to the docker socket with the parameter `docker_host`,
36+
i.e. `docker_host: "unix://{{ ansible_env.HOME }}/.rd/docker.sock"`.

app/app_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import unittest
2+
3+
from app import app
4+
5+
6+
class TestApp(unittest.TestCase):
7+
def setUp(self):
8+
self.client = app.test_client()
9+
10+
def test_hello_world(self):
11+
response = self.client.get("/")
12+
self.assertEqual(response.status_code, 200)
13+
self.assertEqual(response.data, b"Hello, World!")
14+
15+
16+
if __name__ == "__main__":
17+
unittest.main()

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
ansible==10.3.0
2+
ansible-compat==24.9.1
3+
ansible-core==2.17.5
4+
ansible-lint==24.9.2
15
blinker==1.6.3 ; python_version >= "3.10" and python_version < "4.0"
26
click==8.1.7 ; python_version >= "3.10" and python_version < "4.0"
37
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"

0 commit comments

Comments
 (0)