diff options
Diffstat (limited to 'roles/services/containers/homer')
-rw-r--r-- | roles/services/containers/homer/handlers/main.yml | 4 | ||||
-rw-r--r-- | roles/services/containers/homer/tasks/main.yml | 122 |
2 files changed, 126 insertions, 0 deletions
diff --git a/roles/services/containers/homer/handlers/main.yml b/roles/services/containers/homer/handlers/main.yml new file mode 100644 index 0000000..5463835 --- /dev/null +++ b/roles/services/containers/homer/handlers/main.yml | |||
@@ -0,0 +1,4 @@ | |||
1 | - name: restart nginx | ||
2 | service: | ||
3 | name: nginx | ||
4 | state: restarted | ||
diff --git a/roles/services/containers/homer/tasks/main.yml b/roles/services/containers/homer/tasks/main.yml new file mode 100644 index 0000000..b646d12 --- /dev/null +++ b/roles/services/containers/homer/tasks/main.yml | |||
@@ -0,0 +1,122 @@ | |||
1 | - name: set image fact | ||
2 | set_fact: | ||
3 | image: b4bz/homer:v23.05.1 | ||
4 | |||
5 | - name: set other facts | ||
6 | vars: | ||
7 | array: "{{ image.split('/', 1) }}" | ||
8 | set_fact: | ||
9 | repo_tag: "{{ array.1 }}" | ||
10 | custom_registry: "{{ docker_registry_url + '/' + docker_registry_username }}" | ||
11 | |||
12 | - name: create homer directory | ||
13 | file: | ||
14 | path: "{{ docker_home }}/homer" | ||
15 | state: directory | ||
16 | owner: "{{ docker_username }}" | ||
17 | group: "{{ docker_username }}" | ||
18 | mode: '0755' | ||
19 | |||
20 | - name: login to docker registry | ||
21 | become: yes | ||
22 | become_user: "{{ docker_username }}" | ||
23 | environment: | ||
24 | XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" | ||
25 | docker_login: | ||
26 | docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" | ||
27 | registry_url: "{{ docker_registry_url }}" | ||
28 | username: "{{ docker_registry_username }}" | ||
29 | password: "{{ docker_registry_password }}" | ||
30 | |||
31 | - name: get homer image | ||
32 | become: yes | ||
33 | become_user: "{{ docker_username }}" | ||
34 | environment: | ||
35 | XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" | ||
36 | docker_image: | ||
37 | name: "{{ image }}" | ||
38 | repository: "{{ custom_registry }}/{{ repo_tag }}" | ||
39 | push: yes | ||
40 | docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" | ||
41 | source: pull | ||
42 | force_source: yes | ||
43 | |||
44 | - name: create homer assets directory | ||
45 | file: | ||
46 | path: "{{ docker_home }}/homer/assets" | ||
47 | state: directory | ||
48 | owner: "{{ docker_username }}" | ||
49 | group: "{{ docker_username }}" | ||
50 | mode: '0755' | ||
51 | |||
52 | - name: synchronize homer assets | ||
53 | synchronize: | ||
54 | src: "{{ homer_assets_dir }}" | ||
55 | dest: "{{ docker_home }}/homer/assets/" | ||
56 | delete: yes | ||
57 | |||
58 | - name: set permissions on homer assets | ||
59 | file: | ||
60 | path: "{{ docker_home }}/homer/assets/" | ||
61 | owner: "{{ docker_username }}" | ||
62 | group: "{{ docker_username }}" | ||
63 | mode: u=rwX,g=rX,o=rX | ||
64 | recurse: yes | ||
65 | |||
66 | - name: set permissions on homer assets | ||
67 | file: | ||
68 | path: "{{ docker_home }}/homer/assets/" | ||
69 | state: directory | ||
70 | owner: "{{ docker_username }}" | ||
71 | group: "{{ docker_username }}" | ||
72 | mode: '0755' | ||
73 | recurse: no | ||
74 | |||
75 | - name: create homer docker network | ||
76 | docker_network: | ||
77 | name: "{{ homer_network_name }}" | ||
78 | docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" | ||
79 | driver: bridge | ||
80 | ipam_config: | ||
81 | - subnet: "{{ homer_subnet }}" | ||
82 | gateway: "{{ homer_gateway }}" | ||
83 | |||
84 | - name: create and deploy homer container | ||
85 | become: yes | ||
86 | become_user: "{{ docker_username }}" | ||
87 | environment: | ||
88 | XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" | ||
89 | docker_container: | ||
90 | name: "homer" | ||
91 | hostname: "homer" | ||
92 | image: "{{ custom_registry }}/{{ repo_tag }}" | ||
93 | docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" | ||
94 | purge_networks: yes | ||
95 | networks: | ||
96 | - name: "{{ homer_network_name }}" | ||
97 | ipv4_address: "{{ homer_ipv4 }}" | ||
98 | ports: | ||
99 | - "127.0.0.1:8001:8080" | ||
100 | state: 'started' | ||
101 | recreate: yes | ||
102 | restart_policy: unless-stopped | ||
103 | volumes: | ||
104 | - "{{ docker_home }}/homer/assets:/www/assets" | ||
105 | |||
106 | - name: deploy nginx configuration | ||
107 | notify: restart nginx | ||
108 | register: nginx_config | ||
109 | copy: | ||
110 | src: "{{ homer_nginx_config }}" | ||
111 | dest: /etc/nginx/sites-available/homer.conf | ||
112 | owner: root | ||
113 | group: root | ||
114 | mode: '0644' | ||
115 | |||
116 | - name: symlink site | ||
117 | file: | ||
118 | src: /etc/nginx/sites-available/homer.conf | ||
119 | dest: /etc/nginx/sites-enabled/homer.conf | ||
120 | owner: root | ||
121 | group: root | ||
122 | state: link | ||