Skip to content

Commit de6c32e

Browse files
authored
Merge pull request #8 from tjann7/lab05
Lab05
2 parents bd0ce7e + 20623ce commit de6c32e

File tree

26 files changed

+373
-3156
lines changed

26 files changed

+373
-3156
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
key.json
2+
.terraform*
3+
terraform.tfstate*
4+
15
# Byte-compiled / optimized / DLL files
26
__pycache__/
37
*.py[cod]

ansible/ANSIBLE.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Ansible Playbook Deployment output:
2+
3+
```bash
4+
tjann@fedora:~/DevOps-Course/ansible$ ansible-playbook playbooks/dev/main.yaml | tail -n 50
5+
[WARNING]: Platform linux on host yandex_vm is using the discovered Python
6+
interpreter at /usr/bin/python3.10, but future installation of another Python
7+
interpreter could change the meaning of that path. See
8+
https://docs.ansible.com/ansible-
9+
core/2.18/reference_appendices/interpreter_discovery.html for more information.
10+
11+
PLAY [install Docker] **********************************************************
12+
13+
TASK [Gathering Facts] *********************************************************
14+
ok: [yandex_vm]
15+
16+
TASK [docker : Install Docker & compose] ***************************************
17+
included: /home/tjann/DevOps-Course/ansible/roles/docker/tasks/install_docker.yml for yandex_vm
18+
19+
TASK [docker : Install prerequisites] ******************************************
20+
ok: [yandex_vm]
21+
22+
TASK [docker : Add Docker official GPG key] ************************************
23+
ok: [yandex_vm]
24+
25+
TASK [docker : Add Docker repository] ******************************************
26+
ok: [yandex_vm]
27+
28+
TASK [docker : Update package cache] *******************************************
29+
changed: [yandex_vm]
30+
31+
TASK [docker : Install Docker] *************************************************
32+
ok: [yandex_vm]
33+
34+
TASK [docker : Ensure Docker is running] ***************************************
35+
ok: [yandex_vm]
36+
37+
TASK [docker : Install Docker Compose] *****************************************
38+
included: /home/tjann/DevOps-Course/ansible/roles/docker/tasks/install_compose.yml for yandex_vm
39+
40+
TASK [docker : Install Docker Compose] *****************************************
41+
ok: [yandex_vm]
42+
43+
PLAY RECAP *********************************************************************
44+
yandex_vm : ok=10 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
45+
```
46+
# Inventory Details
47+
48+
## Inventory list
49+
50+
```bash
51+
tjann@fedora:~/DevOps-Course/ansible$ ansible-inventory -i inventory/default_aws_ec2.yml --list
52+
{
53+
"_meta": {
54+
"hostvars": {
55+
"yandex_vm": {
56+
"ansible_host": "89.169.129.233",
57+
"ansible_ssh_private_key_file": "~/.ssh/yandex_vm",
58+
"ansible_user": "tjann"
59+
}
60+
}
61+
},
62+
"all": {
63+
"children": [
64+
"ungrouped"
65+
]
66+
},
67+
"ungrouped": {
68+
"hosts": [
69+
"yandex_vm"
70+
]
71+
}
72+
}
73+
```
74+
75+
## Inventory Structure
76+
77+
```bash
78+
tjann@fedora:~/DevOps-Course/ansible$ ansible-inventory -i inventory/default_aws_ec2.yml --graph
79+
@all:
80+
|--@ungrouped:
81+
| |--yandex_vm
82+
```
83+
84+

ansible/ansible.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[defaults]
2+
inventory = inventory/
3+
playbook_dir = playbooks/
4+
roles_path = roles/
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
ec2:
2-
vars:
3-
ansible_user: admin
4-
ansible_ssh_private_key_file: ~/.ssh/id_ed25519
5-
hosts:
6-
local
7-
81

2+
---
3+
all:
4+
hosts:
5+
yandex_vm:
6+
ansible_host: 89.169.129.233
7+
ansible_user: tjann
8+
ansible_ssh_private_key_file: ~/.ssh/yandex_vm

ansible/playbooks/dev/main.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
- hosts: all
1+
2+
---
3+
- name: install Docker
4+
hosts: all
5+
become: true
26
roles:
3-
- geerlingguy.docker
7+
- role: docker

ansible/roles/docker/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,40 @@
11
# Docker Role
22

3+
4+
This role installs and configures Docker and Docker Compose.
5+
6+
## Requirements
7+
8+
- Ansible 2.10+
9+
- Ubuntu 22.04
10+
- 'sudo' privileges on the target machine
11+
12+
## Role Variables
13+
14+
- `docker_version`: The version of Docker to install (default: `latest`).
15+
- `docker_compose_version`: The version of Docker Compose to install (default: `1.29.2`).
16+
17+
## Example Playbook
18+
19+
```yaml
20+
- name: install Docker
21+
hosts: all
22+
roles:
23+
- role: docker
24+
```
25+
26+
## Configured Tasks
27+
28+
1. Dependencies installation
29+
2. Docker repository adding
30+
3. Docker installation
31+
4. Docker compose installation
32+
5. Enabling Docker autolaunching (systemctl enable docker)
33+
6. User adding to the 'docker' group
34+
7. Install completion check
35+
36+
37+
=======
338
Docker and Docker Compose installation via Ansible role.
439
540
## Requirements
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
---
2-
- name: Install docker-compose plugin.
3-
package:
1+
2+
- name: Install Docker Compose
3+
ansible.builtin.apt:
44
name: "docker-compose-plugin"
5-
state: "present"
6-
notify: restart docker
5+
state: present
Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1-
---
2-
- name: Add Docker GPG key
3-
ansible.builtin.apt_key:
1+
2+
- name: Install prerequisites
3+
apt:
4+
name:
5+
- apt-transport-https
6+
- ca-certificates
7+
- curl
8+
- software-properties-common
9+
- python3-pip
10+
state: present
11+
update_cache: yes
12+
13+
- name: Add Docker official GPG key
14+
apt_key:
415
url: https://download.docker.com/linux/ubuntu/gpg
516
state: present
617

7-
- name: Add Docker apt repository
8-
ansible.builtin.apt_repository:
9-
repo: deb https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
18+
- name: Add Docker repository
19+
apt_repository:
20+
repo: "deb [arch={{ ansible_architecture }}] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
1021
state: present
1122

12-
- name: Install Docker packages.
13-
package:
14-
name:
15-
- "docker-ce"
16-
- "docker-ce-cli"
17-
- "containerd.io"
18-
state: "present"
19-
update_cache: true
20-
notify: restart docker
23+
- name: Update package cache
24+
apt:
25+
update_cache: yes
26+
27+
- name: Install Docker
28+
apt:
29+
name:
30+
- docker-ce
31+
- docker-ce-cli
32+
- containerd.io
33+
state: present
34+
update_cache: yes
2135

22-
- name: Start Docker service.
23-
ansible.builtin.systemd:
24-
name: docker
25-
enabled: true
26-
state: started
27-
28-
- name: Add user to Docker group
29-
ansible.builtin.user:
30-
name: "{{ ansible_user }}"
31-
groups: docker
32-
append: true
33-
notify: restart docker
36+
- name: Ensure Docker is running
37+
systemd:
38+
name: docker
39+
state: started
40+
enabled: true
41+
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
---
2-
- name: Install Docker
3-
ansible.builtin.include_tasks: install_docker.yml
1+
2+
- name: Install Docker & compose
3+
include_tasks: install_docker.yml
44

55
- name: Install Docker Compose
6-
ansible.builtin.include_tasks: install_compose.yml
6+
include_tasks: install_compose.yml
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
- name: Install Docker Compose
2+
ansible.builtin.apt:
3+
name: "docker-compose-plugin"
4+
state: present
5+

0 commit comments

Comments
 (0)