blob: ed5430bff8e0588e1ff2e2b4f21dbd1707be4a97 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
---
- name: Manage extinct_potato's personal cloud
hosts: all
vars:
d_stuff: "/home/{{ ansible_ssh_user }}/dstuff"
tasks:
- name: Ensure Python3 is default
become: yes
community.general.alternatives:
name: python
path: /usr/bin/python3
link: /usr/bin/python
- name: Ensure initial prerequisites
become: yes
apt:
update_cache: yes
pkg:
- git
- apt-transport-https
- ca-certificates
- curl
- software-properties-common
- python3-pip
- virtualenv
- python3-setuptools
- python3-docker
- python3-requests
- name: Add Docker GPG key
become: yes
apt_key:
url: https://download.docker.com/linux/debian/gpg
state: present
- name: Add Docker repository
become: yes
apt_repository:
repo: deb https://download.docker.com/linux/debian buster stable
state: present
- name: Install Docker
become: yes
apt:
update_cache: yes
pkg:
- docker-ce
- docker-ce-cli
- containerd.io
- name: Install docker-compose
pip:
name: docker-compose
- name: Add the current SSH user to Docker group
become: yes
user:
name: "{{ ansible_ssh_user }}"
groups: docker
append: yes
- name: Ensure Docker service is enabled
become: yes
ansible.builtin.systemd:
name: docker
state: started
enabled: yes
- name: Create a network for related containers
community.docker.docker_network:
name: web
- name: Ensure directory for stuff
file:
path: '{{ ansible_env.HOME }}/d'
state: directory
- name: Ensure the deploy key
copy:
src: "{{ item }}"
dest: "{{ ansible_env.HOME }}/.ssh/"
mode: 0600
with_fileglob:
- secrets/id_rsa*
- name: Clone the repository with compose files
git:
repo: 'ssh://git@git.hopeburn.eu:42367/dockerstuff/personal-cloud-docker-stuff.git'
dest: "{{ d_stuff }}"
accept_hostkey: yes
register: d_stuff_ret
- name: Update generic containers
when: d_stuff_ret.changed
block:
- name: List generic container sets
find:
paths: "{{ d_stuff }}"
patterns: "*"
recurse: no
file_type: directory
register: generic_containers
- name: List files
debug:
msg: "{{ [item.path] }}"
with_items: "{{ generic_containers.files }}"
- name: Tear down containers
community.docker.docker_compose:
project_src: "{{ [item.path] }}"
state: absent
debug: yes
with_items: "{{ generic_containers.files }}"
- name: Update and start containers
community.docker.docker_compose:
project_src: "{{ [item.path] }}"
state: present
stopped: yes
build: yes
pull: yes
with_items: "{{ generic_containers.files }}"
|