-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.yml
167 lines (141 loc) · 4.7 KB
/
main.yml
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
---
- name: Homelab
hosts: prod
# hosts: rpi3
become: true
vars_files:
- ./vars/docker-vars.yml
- ./vars/hyperhdr-vars.yml
- ./vars/hyperion-vars.yml
- ./secrets/slack_code.yml
pre_tasks:
- name: PRE TASK | Ensure apt cache is up to date
ansible.builtin.apt:
update_cache: true
cache_valid_time: 10800
upgrade: "yes"
when:
- ansible_facts.os_family == "Debian"
- name: PRE TASK | Ensure Nala is installed on performant devices
ansible.builtin.apt:
name: nala
state: present
when:
- ansible_memtotal_mb > 2000
- ansible_facts.os_family == "Debian"
# - name: PRE TASK | Ensure wifi is disabled on wired devices
# ansible.builtin.cron:
# name: "Disable wifi"
# special_time: reboot
# job: ifconfig wlan0 down
# when: "'hyperhdr' is not in ansible_hostname"
- name: PRE TASK | Mount SMB shares
ansible.builtin.shell:
cmd: mount -a
when: "'hyperhdr' is not in ansible_hostname"
handlers:
- name: HANDLER | Restart services
community.docker.docker_compose_v2:
project_src: /home/{{ ansible_user }}/homelab/{{ item }}/
state: present
recreate: always
with_items:
- "homer"
- "homepage"
- "portainer-traefik"
- name: HANDLER | Restart PiHole
community.docker.docker_compose_v2:
project_src: /home/{{ ansible_user }}/homelab/pihole/pihole-docker/
state: present
recreate: always
# - name: HANDLER | Restart sonos streaming
tasks:
- name: Setup Docker
ansible.builtin.import_tasks:
file: tasks/docker.yml
when: "'hyperhdr' is not in ansible_hostname"
- name: Clone Git Repos
ansible.builtin.import_tasks:
file: tasks/git-repo.yml
when: "'hyperhdr' is not in ansible_hostname"
- name: Prepare Home Assistant deployment
ansible.builtin.import_tasks:
file: tasks/home-assistant.yml
when: "'rpi4-2' is in ansible_hostname"
- name: Prepare Docker deployment
ansible.builtin.import_tasks:
file: tasks/docker-env.yml
when: "'hyperhdr' is not in ansible_hostname"
- name: Deploy Docker Containers
ansible.builtin.import_tasks:
file: tasks/docker-deploy.yml
when: "'hyperhdr' is not in ansible_hostname"
- name: Setup CD
ansible.builtin.import_tasks:
file: tasks/cd.yml
when: "'rpi4-1' is in ansible_hostname"
# - name: Deploy hyperhdr
# ansible.builtin.import_tasks:
# file: tasks/hyperhdr.yml
# when: "'hyperhdr' is in ansible_hostname"
- name: Deploy hyperhdr
ansible.builtin.import_role:
name: aleksanderbl29.hyperhdr
vars:
disable_verification: true
when: "'hyperhdr' is in ansible_hostname"
- name: Deploy sonos-stream
ansible.builtin.import_role:
name: aleksanderbl29.sonos_stream
vars:
# disable_verification: true
when: "'hyperhdr' is in ansible_hostname"
- name: Setup figurine
ansible.builtin.import_role:
name: ironicbadger.figurine
become: true
when:
- ansible_memtotal_mb > 2000
post_tasks:
# - name: POST TASK | Prune old Docker images and volumes
# community.docker.docker_prune:
# containers: true
# images: true
# networks: true
# volumes: true
# builder_cache: true
- name: POST TASK | Purge old Docker images
ansible.builtin.command:
cmd: docker system prune --all --force --volumes
# changed_when: false
when: "'hyperhdr' is not in ansible_hostname"
- name: POST TASK | Get uptime
ansible.builtin.command:
cmd: uptime
changed_when: false
register: uptime
- name: POST TASK | Print uptime
ansible.builtin.debug:
msg: "{{ uptime.stdout }}"
- name: POST TASK | Get temperature of devices
ansible.builtin.command:
cmd: vcgencmd measure_temp
changed_when: false
register: temperature
- name: POST TASK | Print temperature
ansible.builtin.debug:
msg: "{{ temperature.stdout }}"
- name: POST TASK | Check voltage throttling
ansible.builtin.command:
cmd: vcgencmd get_throttled
changed_when: false
register: throttling
- name: POST TASK | Print voltage throttling
ansible.builtin.debug:
msg: "{{ throttling.stdout }}"
- name: POST TASK | Send Slack notification
community.general.slack:
token: "{{ slack_webhook }}"
msg: "Run on {{ ansible_hostname }} complete and the device is at {{ temperature.stdout }}"
channel: "#ansible"
username: "Ansible"