Skip to content

Commit 935d700

Browse files
committed
add ansible files to automate deployment and updates
1 parent 73be69c commit 935d700

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

ansible/inventory.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
staging:
2+
hosts:
3+
staging:
4+
ansible_host: mystaging.warp-charger.com
5+
6+
production:
7+
hosts:
8+
warp-charger:
9+
ansible_host: my.warp-charger.com
10+
seb:
11+
ansible_host: my.smart-energy-broker.com
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
- name: Change production version
2+
hosts: staging
3+
tasks:
4+
- name: Update packages
5+
become: true
6+
ansible.builtin.apt:
7+
update_cache: yes
8+
upgrade: safe
9+
autoremove: true
10+
11+
- name: Check if reboot is required
12+
stat:
13+
path: /var/run/reboot-required
14+
register: reboot_required_file
15+
16+
- name: Reboot if required
17+
reboot:
18+
when: reboot_required_file.stat.exists
19+
20+
- name: checkout git
21+
ansible.builtin.git:
22+
repo: https://github.com/Tinkerforge/esp32-remote-access.git
23+
dest: /home/freddy/esp32-remote-access
24+
version: v1.2.38
25+
update: yes
26+
clone: yes
27+
register: git_checkout
28+
29+
- name: Verify checked out tag
30+
ansible.builtin.command: git describe --tags --exact-match
31+
args:
32+
chdir: /home/freddy/esp32-remote-access
33+
register: git_tag
34+
35+
- name: Stop Docker containers
36+
community.docker.docker_compose_v2:
37+
project_src: /home/freddy/esp32-remote-access/docker
38+
state: stopped
39+
when: git_checkout.changed
40+
41+
- name: Pull and rerun docker images
42+
community.docker.docker_compose_v2:
43+
build: always
44+
pull: always
45+
project_src: /home/freddy/esp32-remote-access/docker
46+
when: git_checkout.changed
47+
48+
- name: Show current tag
49+
ansible.builtin.debug:
50+
msg: "Checked out tag: {{ git_tag.stdout | default('none') }}"
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
- name: Change production version
2+
hosts: staging
3+
tasks:
4+
- name: Update packages
5+
become: true
6+
ansible.builtin.apt:
7+
update_cache: yes
8+
upgrade: safe
9+
autoremove: true
10+
11+
- name: Check if reboot is required
12+
stat:
13+
path: /var/run/reboot-required
14+
register: reboot_required_file
15+
16+
- name: Reboot if required
17+
reboot:
18+
when: reboot_required_file.stat.exists
19+
20+
- name: checkout git
21+
ansible.builtin.git:
22+
repo: https://github.com/Tinkerforge/esp32-remote-access.git
23+
dest: /home/freddy/esp32-remote-access
24+
version: main
25+
update: yes
26+
clone: yes
27+
register: git_checkout
28+
29+
- name: Verify checked out tag
30+
ansible.builtin.command: git describe --tags --exact-match
31+
args:
32+
chdir: /home/freddy/esp32-remote-access
33+
register: git_tag
34+
changed_when: false
35+
failed_when: git_tag.rc not in [0, 128]
36+
37+
- name: Stop Docker containers
38+
community.docker.docker_compose_v2:
39+
project_src: /home/freddy/esp32-remote-access/docker
40+
state: stopped
41+
when: git_checkout.changed
42+
43+
- name: Pull and rerun docker images
44+
community.docker.docker_compose_v2:
45+
build: always
46+
pull: always
47+
project_src: /home/freddy/esp32-remote-access/docker
48+
when: git_checkout.changed
49+
50+
- name: Show current tag
51+
ansible.builtin.debug:
52+
msg: "Checked out tag: {{ git_tag.stdout | default('none') }}"

0 commit comments

Comments
 (0)