From 10a11daa7d8bd9294ef69c639956bd07c92092cb Mon Sep 17 00:00:00 2001 From: chatton Date: Thu, 8 Jun 2023 22:47:03 +0100 Subject: [PATCH] add diun to qnap and snunmu --- host_vars/qnap.yml | 8 + host_vars/snunmu.yml | 7 + roles/setup_hosted_services/handlers/main.yml | 3 + roles/setup_hosted_services/tasks/main.yml | 37 +++- .../templates/diun-config.j2 | 24 +++ roles/setup_hosted_services/templates/diun.j2 | 27 +++ vault_vars/qnap-vault.yml | 164 +++++++++--------- 7 files changed, 181 insertions(+), 89 deletions(-) create mode 100644 roles/setup_hosted_services/templates/diun-config.j2 create mode 100644 roles/setup_hosted_services/templates/diun.j2 diff --git a/host_vars/qnap.yml b/host_vars/qnap.yml index 46143f6..7240707 100644 --- a/host_vars/qnap.yml +++ b/host_vars/qnap.yml @@ -47,6 +47,13 @@ portainer_required_files: dest_directory: /etc/config/OliveTin handler: restart-olivetin +portainer_required_templates: + - source_file: diun-config.j2 + dest_file_name: diun-config.yml + dest_directory: /etc/config/diun + handler: restart-diun + + portainer_endpoint: 2 services: - name: vpn-stack @@ -82,3 +89,4 @@ services: - name: pihole - name: paperless - name: gotify + - name: diun diff --git a/host_vars/snunmu.yml b/host_vars/snunmu.yml index e096d37..a4e714c 100644 --- a/host_vars/snunmu.yml +++ b/host_vars/snunmu.yml @@ -1,6 +1,12 @@ --- vault_file: vault_vars/qnap-vault.yml +portainer_required_templates: + - source_file: diun-config.j2 + dest_file_name: diun-config.yml + dest_directory: /etc/config/diun + handler: restart-diun + portainer_endpoint: 23 services: - name: linkding @@ -11,6 +17,7 @@ services: dashy: false dashdot: true glances: true + - name: diun ansible_pull_path: /usr/local/bin/ansible-pull diff --git a/roles/setup_hosted_services/handlers/main.yml b/roles/setup_hosted_services/handlers/main.yml index 8a24310..0006e3e 100644 --- a/roles/setup_hosted_services/handlers/main.yml +++ b/roles/setup_hosted_services/handlers/main.yml @@ -5,5 +5,8 @@ - name: restart-olivetin ansible.builtin.command: docker restart olivetin +- name: restart-diun + ansible.builtin.command: docker restart diun + - name: restart-docker-volume-backup ansible.builtin.command: docker restart docker-volume-backup diff --git a/roles/setup_hosted_services/tasks/main.yml b/roles/setup_hosted_services/tasks/main.yml index 2e5755c..95e3f2b 100644 --- a/roles/setup_hosted_services/tasks/main.yml +++ b/roles/setup_hosted_services/tasks/main.yml @@ -11,7 +11,7 @@ with_items: - ubuntu -- name: Create required directories. +- name: Create required directories (files). ansible.builtin.file: path: '{{ file_item.dest_directory }}' state: directory @@ -32,6 +32,27 @@ loop_var: file_item notify: "{{ file_item.handler }}" +- name: Create required directories (templates). + ansible.builtin.file: + path: '{{ file_template.dest_directory }}' + state: directory + mode: '0755' + with_items: "{{ portainer_required_templates }}" + loop_control: + loop_var: file_template + +- name: Create required templates. + ansible.builtin.template: + src: "{{ file_template.source_file }}" + dest: "{{ file_template.dest_directory }}/{{ file_template.dest_file_name }}" + owner: root + group: root + mode: 0440 + with_items: "{{ portainer_required_templates }}" + loop_control: + loop_var: file_template + notify: "{{ file_template.handler }}" + - name: Create external docker networks. docker_network: name: '{{ item }}' @@ -49,14 +70,14 @@ loop_var: portainer_stack - name: Install Ansible pull - tags: ["cron"] + tags: [ "cron" ] ansible.builtin.pip: name: - ansible # TODO: need to specify ansible pull directly, it doesn't find it when it's in PATH - name: Ensure Nightly Cron Backups - tags: ["cron"] + tags: [ "cron" ] ansible.builtin.cron: name: backup docker volumes (nightly) weekday: "*" @@ -64,20 +85,20 @@ hour: "{{ cron_hour }}" user: "{{ homelab_user }}" job: > - {{ ansible_pull_path }} - -U https://github.com/chatton/ansible-homelab playbooks/backup-docker-volumes.yml -e schedule=nightly >> ~/logs/nightly.log 2>&1 + {{ ansible_pull_path }} + -U https://github.com/chatton/ansible-homelab playbooks/backup-docker-volumes.yml -e schedule=nightly >> ~/logs/nightly.log 2>&1 cron_file: ansible_nightly_docker_volume_backup state: present - name: Ensure Monthly Cron Backups - tags: ["cron"] + tags: [ "cron" ] ansible.builtin.cron: name: backup docker volumes (monthly) month: "*" day: "0" user: "{{ homelab_user }}" job: > - {{ ansible_pull_path }} - -U https://github.com/chatton/ansible-homelab playbooks/backup-docker-volumes.yml -e schedule=monthly >> ~/logs/monthly.log 2>&1 + {{ ansible_pull_path }} + -U https://github.com/chatton/ansible-homelab playbooks/backup-docker-volumes.yml -e schedule=monthly >> ~/logs/monthly.log 2>&1 cron_file: ansible_monthly_docker_volume_backup state: present diff --git a/roles/setup_hosted_services/templates/diun-config.j2 b/roles/setup_hosted_services/templates/diun-config.j2 new file mode 100644 index 0000000..fef91e4 --- /dev/null +++ b/roles/setup_hosted_services/templates/diun-config.j2 @@ -0,0 +1,24 @@ +db: + path: diun.db + +watch: + workers: 10 + schedule: "0 */6 * * *" + jitter: 30s + # always want notification if an update is available + firstCheckNotif: true + +notif: + gotify: + endpoint: https://gotify.cianhatton.ie + token: {{ diun_gotify_token }} + priority: 1 + timeout: 10s + templateTitle: "{% raw %}{{ .Entry.Image }}{% endraw %} released" + templateBody: | + Docker tag {% raw %}{{ .Entry.Image }}{% endraw %} which you subscribed to through {% raw %}{{ .Entry.Provider }}{% endraw %} provider has been released. + +providers: +# check these separate to the docker system + File: + filename: /data/config.yml diff --git a/roles/setup_hosted_services/templates/diun.j2 b/roles/setup_hosted_services/templates/diun.j2 new file mode 100644 index 0000000..ef7118f --- /dev/null +++ b/roles/setup_hosted_services/templates/diun.j2 @@ -0,0 +1,27 @@ +--- +version: "3.5" + +services: + diun: + image: crazymax/diun:latest + container_name: diun + command: serve + volumes: + - data:/data + - /var/run/docker.sock:/var/run/docker.sock + - /etc/config/diun/diun-config.yml:/data/config.yml + environment: + - TZ=Europe/Dublin + - LOG_LEVEL=debug + - LOG_JSON=false + - DIUN_WATCH_WORKERS=20 + - DIUN_WATCH_SCHEDULE=0 */6 * * * + - DIUN_WATCH_JITTER=30s + - DIUN_PROVIDERS_DOCKER=true + - DIUN_PROVIDERS_DOCKER_WATCHBYDEFAULT=true + - CONFIG=/data/config.yml + labels: + - diun.enable=true + restart: always +volumes: + data: diff --git a/vault_vars/qnap-vault.yml b/vault_vars/qnap-vault.yml index 8e8f43c..1a74ce9 100644 --- a/vault_vars/qnap-vault.yml +++ b/vault_vars/qnap-vault.yml @@ -1,82 +1,84 @@ $ANSIBLE_VAULT;1.1;AES256 -62316137626266623235376138386561316432373863656439333461663862633038386666373436 -6230633363316635643334326434396436383962386230610a646136386362363961613434343539 -64326462333031656438366466373530656239656238633137333530346265333263363162356534 -6464613631616230390a666235303763346439323436633730306138376666393461383336626661 -39323432376433613132643163343937326166356133616366386135633263646432313765383938 -64613361363463343336643766386532386465616437626463356661306431336164373462653664 -39313235383235383035303732613664393631363933636563663836613333653430313265643639 -35646439616235363835386366313730646631316331333536353864383865626664656430383765 -33313162393963343635363330396337353064636335623538643838323333666434613164393732 -38653830323335343134626237316434356635663033353832333639313738653464613538643431 -30386161333036323730613763323736306564663537366365396264336433386331376263323938 -64306334396335306165323333316332303461343433333866386662336630623766616537306133 -64353863333731306336643830626338386564643432343265646334633236643666646261303962 -63323865376338353034613338376137376234656563313866363962656133656330623133623366 -63373662386666343961346538346165613436613937383239386364666438663231363435653531 -34376539303236643362333264613864636239336138363836323638376132323465393838373932 -65663563373463653039343235363639326362396239613836343331303730346436393231316635 -30666462623435356339396462333138313964343161616666663034386337383236346465316635 -34623436363663396564306261356531653963613433346231353837303530353534346537626466 -63303031303062353237306163623634383634353536643833613631656262336462643061636633 -33363638386332366565613734373638663266323835353962316437373235316433663265646265 -63633639313530353963313536303338306338613133346231373935646363393139663737356535 -32653738383066333037353030393163326233353766316566653430333231626437623263396135 -32343766373162383238353562386435376162303865353836643739343263636137313035633537 -30333263663530303139373233353466666636396132316636313036643562383165363238346233 -31363532333137336633646638386139623530333161363165363533303337383130356266656434 -37633461333166383366646431643732336332326462616234376265373763313038623666643737 -32316439306634303932663964343331393038303339316261333266653131346631393261363732 -30396235613634313865393530633036613930636437643263306530356136346666633566393066 -36313437376338656232306431303834303230313964326261393834333633653138633634663432 -30376361653361663238323334343039616533343835396163626139653932636633626266336161 -31363738383235643963663161633662363736323139613761636435366434656661613632343166 -63316437643665376536303739636635633662306666336566383836656366656262363330306366 -64336436653263323764633334376162663638613236373639326634333366636661383032366636 -32613864333365633433363366636234626537666438663137666362623463373835376639633061 -32343363613864303839356262653635363038636361626430666564366139323462323535616430 -64366131353634353636643462623138623064613438386134383165363937396630363135616636 -33346337306533343839613436336538666239363630623562616665353266393164313537626164 -34363430613437303065386132383530623862343736323465376338633138636235633036353434 -39316463666533623765376238653161623737393161616264666431396465383832303562343035 -32383265626463353137313831363433636339363234346662663830666266633730333232643066 -39353938623937663438316463653162313432656531323032306561363362346366336131363934 -35333830656331636437663437353537323533356539393935343734636330363562346530613661 -64363738656362306263313336306464373330333632343137313639346333386465353861363261 -36643335633936313235346664663464376530303466376338376335663230633134353334643266 -62323531396133306663623965636135303031626262393037316532653761353735633939393731 -31653937366162623464336339383633383733313864303436313463643764663961353562616163 -61616262666461363265353030386636653062383464393266366562393731393763613236383666 -35623539356236613164303635303563333739346334643936323266653136643837356466373139 -33663730343930326235353234313061373366666163653030343032393233643837363234313831 -31393466653835656130393733326532656435373234653562373736393435306431623133353233 -36316665623966633732366137336135383662323561333061346435336431633433333538303265 -62356465643665303862343136613433373362623937323233666130633831653839643934613666 -31386662373961636362383061363563343533343637376537316163333734613565646265623266 -39356264323534383734636638653162336166353232356361653330643133343366366162383930 -37323839656339616238626261613566633433616164363766616330623938666261303332353135 -34386332373237363131316363303431383463663366623135663630663161326162623834313666 -63303862656366336634313463623335303661613932326131373463623434633964336232333437 -38306266373162626330336333306330366164373863303531303737646465343332373238613364 -34336332336162616239373534613531313834356661633933646438323632353963323736613361 -65336431376265316337393132306264326634363734396564663161663339666239323736643466 -38353865383930626166313066376137323231613934626139376161636430616132303431333561 -34643762656137646632373337653266633434386535353231643339383363616165373462326636 -37656365366433353866653563653937333332643965376632323530336531343437343165376463 -31353964383234623538303533343565303436373737636335356134373766373466633237646131 -31353933323035626363663432383639636532643835323761396239336134613438323061306164 -33613863623337343761313832346161333932336534643331313430643433613332653631623635 -64376633313135396533336362636261613533333065383862653661343533656262343638653739 -64303665343033613239643235363364323736663239383161616539353963373733356566383864 -65633434303236303831396337356438616466333537666434626363393339626265646534393734 -63666235623733336531623731353739643035313634393738313731303965646164643165323230 -36636337616533353563616330643633313732323938323033303739663130363039393262343030 -35383361316266356466323831313333626465303766623239356661623937663038633061333162 -30393436353932396564316565343331303735646662646663393133633763353331626333633861 -65646335343966356339636133323064313632363932303735313164663262623631396433663833 -64666562376335363766326363343336653136376437613566653630653030323839343737656434 -61376631303931663937393131623535613865396362373166633936616563336432363632646537 -63653038313161633562626466616166333639633364663830363638656237633733393739656462 -66656631356433383863326238653166333530653563383038313965623030343861373638613432 -61383766656333636663316637303066643665373530636438633831653665356164346436333937 -34613461313533623931636437303231393836623839653732333935323136643933 +64613035323837626266306537373333323334626565666666326165653734373739333931653438 +6563393231343138386365323666613637303866363130610a333634326131303033343761656264 +61396565353238353931653964383032643364376335666436666233396263633235646166396362 +3436313935326638360a343235623664616633633061646339376666636538633762666562666233 +38393765636466323964643535636362643734623362643630613535653161646263346638663962 +34393037643438653734316361376438356662313038383933623835386631663162613736626437 +34663530646664643239633764343065386233356465343531646163376434346634343865313331 +62356138616362306333636335346466336264386661313161623737313964326164396537633664 +33336136663665396333343336666534396265343166623664373238383165626164366461393830 +32623465646437626538396263386462323331653438636564636235643234323464623562363637 +39333565363663616138343637343138356233663732613164386530666631316566356535393765 +35326336336665363234643466666533656233643032356464623138383831633539646163666462 +66376566343466306338613262643466383131343634656237396635643531616462303032656434 +32643638636666386238373262646161626363346130636532633338313436346130633130633138 +62306165623034393439333861363461363862383664666363393538303562613063333161623235 +36356562366332386661303538303361356235643033326536653733643461336362636634373164 +63336130306333666261653332646131613933383534623663306431663035353664316662616566 +66326534313165623432373431653564323639393762653038626362323663356565356138303263 +32363232363961323136653264383863373236386237643034643232643866376236666339333461 +37393963376632653338643465393638366265333232343234643039316435653239366339373537 +36323630633363646262373265313331626236363764623339653932343864646165663765323737 +30353263653039363439666464656437386432343537333535616534613065343666396238323263 +38386132613166623532336361383661303462373730306262613135396535623338383166623366 +61323330663036396365316261666338366139656232346539393066306634363962363264636161 +36613661663535373064306661313161336565313534313037353332383265313235306135353761 +32373266396439386539616635373464386236323430346462383437613031313564323833386333 +39653039393531626530666563336266643630326134616438626638353936356263336137376366 +62626138363039643238656333323936333533363835633666323864393762396330386635393331 +64303538383031363435316138663064633135626638623262353965623634653834313835333835 +38643835373538323234383835333366396261336531356238653134653034383532386462353536 +36643964303936626232376136303338306466633831663939656631326233623838383530393431 +30616361393435366265663737363437366362623363376638336531663636336535333131666436 +62336632653236613734333961306630653738373961633532616162386231326137363265653534 +34323366396364623039613230323231613934343761376535653562396236323437623435303034 +31653932613164626534613231653130336636616431383536323133313334663032643362646130 +61323565366538333938393731343863333265383730616238333731376265386131643239653039 +33303332363030613138323462656664353537353166626562323738343036303266346237653861 +37306262613139616137303539376138333662653763323231646237396161393433653966613739 +65333132316534656137366435633237656463373637666464633339333337636238323734636561 +31353466313034336366356134316237376461653835653234633038643561636466376462333666 +30366663343232303364353133303662336433313935666666356630323530363530633265396432 +36636632363365306634643133643137343838393061306165663835663466336336306433323532 +64386362383234663464323363623538346336303937663738366131313065613462323864346262 +61346431393264663264653435316335653632306639313033613035376366666437393931303264 +32646166353062643466313338643164373864633937616662303361343666306333656339333836 +37376438306161646437363566666164366336636232336333613339653863643664643432616333 +65323431626130326436333138643430363162323430656230373636323036373834303534306463 +62376262313965613237336464363837666230313531623234363638313138653237613261306435 +61353237636263306235396639616363616439656434383531306338666663663530663732636630 +65373538636130316239333633633034383366643965383064386164356437333861373835383864 +34313536646562363633386532303633663333336231356139303937316366656138373936373735 +36323863336531633337653465386533333862363432356135386133636564336263326632616530 +30646635653030353839613939326633363339653535616364323734613930393238626665376565 +37653866313936393430383031333031363837393361333334373066623930333261323465386230 +62373638633335383164343832646636363834663937623661323163303561356132623066396366 +63396134373862383336626638313234393936343963646561353561346231343432373666613563 +65616234386266653132333536666438386537613036666263306136343961633763383630313135 +62396466393130376563373539313839333835316666326239666266613739666238613539343165 +62653765346339666631623936663434336566313137666263636632343662373564383665396238 +32653034353061666132393862376264323930396431346261633033346566626630343431336236 +61626437643063393266643333633835666437653936353165646633633135646530333562396437 +62346161656439633561346131363839333637313936393739376237326361336162306266303930 +31353336323365363332343432663964353438643863653135656231353866333736373131656135 +64613834343566396664626236363239653863633435353566336563316137626435636561653831 +33306532373661323136643239613064323061653365303033396330323362363666333638316165 +64316166383136373564643339653938326130386335313839646239383737623466393437393231 +35643162336164623063616538663966643237633839353530653136393062623832646233313139 +31343962663030613433336366333263303434626538393235343862353236663332373066626239 +39333135393163613164376366396536306365663264326661656333656262386234316332323233 +64303930626464646233313638653436383662633438656264616431363265666334386564396637 +61396633633930396334346234663031303861643538636631656630326632363339393339333937 +33396439303863613334376664313134616361323032373631666566383562623431636533633931 +30343431616537323638323966636262646336313532376136653663623364316165363263353932 +61333363633936373433653639333137333266643061643763393765663463303265636332323534 +34323838363131636131616262353765373632323262646137333536393466313031376537373439 +34633536353261633737653035663530633637633035613638356133636533303039326565633061 +30303363633637633436663866653233303332383734313563366536393531646266323231333364 +34663037616136633866306330653766633432336665303235386537306663333862656262386664 +64373031313935633063366663326336653630613633656630326534616665366137636433623635 +32323565646538653439353462373931346263613733386132343139323261363266363764623230 +34343435343164386539383238656437363137613837633738386638656265656639376530366538 +65373435356466333833303830666332613161363163316135633436623138643935386537306537 +353631383239376461336134363732393235