From cff95e0e44cd1d0352662cb07e6a47d50d2500a9 Mon Sep 17 00:00:00 2001 From: Cian Hatton Date: Thu, 8 Sep 2022 20:06:50 +0100 Subject: [PATCH] add pihole --- .../chatton/portainer/FILES.json | 2 +- .../chatton/portainer/MANIFEST.json | 2 +- .../plugins/modules/portainer_stack.py | 2 +- host_vars/qnap.yml | 8 +- host_vars/snunmu.yml | 8 ++ roles/deploy_portainer_stack/tasks/main.yml | 52 ++++----- .../files/dashboards/dashy-config.yml | 20 +++- roles/setup_hosted_services/tasks/main.yml | 3 +- .../templates/dashboards.j2 | 8 +- .../setup_hosted_services/templates/pihole.j2 | 21 ++++ vault_vars/qnap-vault.yml | 107 +++++++++--------- 11 files changed, 147 insertions(+), 86 deletions(-) create mode 100644 roles/setup_hosted_services/templates/pihole.j2 diff --git a/collections/ansible_collections/chatton/portainer/FILES.json b/collections/ansible_collections/chatton/portainer/FILES.json index 99e8905..0697d40 100644 --- a/collections/ansible_collections/chatton/portainer/FILES.json +++ b/collections/ansible_collections/chatton/portainer/FILES.json @@ -60,7 +60,7 @@ "name": "plugins/modules/portainer_stack.py", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "8d7c6e609e3d6d1764768c479a07375b8b43d65a9fc30e7f8cefe1bc48fe7d2b", + "chksum_sha256": "e75fa1655aed9c13955315a80aa9a3f0b54ac1bc386697756bb308e0cfe4ecbb", "format": 1 }, { diff --git a/collections/ansible_collections/chatton/portainer/MANIFEST.json b/collections/ansible_collections/chatton/portainer/MANIFEST.json index 6bee9c9..884cde7 100644 --- a/collections/ansible_collections/chatton/portainer/MANIFEST.json +++ b/collections/ansible_collections/chatton/portainer/MANIFEST.json @@ -23,7 +23,7 @@ "name": "FILES.json", "ftype": "file", "chksum_type": "sha256", - "chksum_sha256": "af38f629ca55ff7f83f84e54ee9496e2fdcd93eb6afce03d79f12dd7d68a5153", + "chksum_sha256": "a3d632538c4fb62677f3dceb2b32648f6688932bfa4354ad1ad21ecd1e031a7d", "format": 1 }, "format": 1 diff --git a/collections/ansible_collections/chatton/portainer/plugins/modules/portainer_stack.py b/collections/ansible_collections/chatton/portainer/plugins/modules/portainer_stack.py index 9ec354f..dc9a8a8 100644 --- a/collections/ansible_collections/chatton/portainer/plugins/modules/portainer_stack.py +++ b/collections/ansible_collections/chatton/portainer/plugins/modules/portainer_stack.py @@ -140,7 +140,7 @@ def handle_state_present(client, module): target_stack_name = module.params["stack_name"] for stack in stacks: - if stack["Name"] == target_stack_name: + if stack["Name"] == target_stack_name and int(stack["EndpointId"]) == module.params["endpoint_id"]: already_exists = True result["stack_id"] = stack["Id"] break diff --git a/host_vars/qnap.yml b/host_vars/qnap.yml index 0c2349f..51bd448 100644 --- a/host_vars/qnap.yml +++ b/host_vars/qnap.yml @@ -15,6 +15,8 @@ mounts: configure_samba: true portainer_host: true +cron_hour: "5" + devices: - uuid: a54c1bde-1400-4975-bf24-08c603ca3a11 # /dev/sdc1 path: /mnt/data/device0 @@ -47,7 +49,10 @@ services: template_vars: default_network: mariadb_net - name: dashboards - template_vars: {} + template_vars: + dashy: true + dashdot: true + glances: true - name: nginx-proxy-manager template_vars: {} - name: plex @@ -64,3 +69,4 @@ services: default_network: mariadb_net - name: olivetin template_vars: {} + - name: pihole diff --git a/host_vars/snunmu.yml b/host_vars/snunmu.yml index f214e5c..0a6400f 100644 --- a/host_vars/snunmu.yml +++ b/host_vars/snunmu.yml @@ -5,5 +5,13 @@ portainer_endpoint: 23 services: - name: linkding template_vars: {} + - name: pihole + - name: dashboards + template_vars: + dashy: false + dashdot: true + glances: true ansible_pull_path: /usr/local/bin/ansible-pull + +cron_hour: "4" diff --git a/roles/deploy_portainer_stack/tasks/main.yml b/roles/deploy_portainer_stack/tasks/main.yml index 03ad358..ae805f3 100644 --- a/roles/deploy_portainer_stack/tasks/main.yml +++ b/roles/deploy_portainer_stack/tasks/main.yml @@ -22,35 +22,35 @@ mode: '0755' with_items: "{{ portainer_stack_directories }}" -- name: "Stack {{ portainer_stack_name }} | Find docker volumes" - ansible.builtin.shell: docker volume ls -f name={{ portainer_stack_name }} --format '{{ '{{' }} .Name {{ '}}' }}' - register: find_volumes - changed_when: false +#- name: "Stack {{ portainer_stack_name }} | Find docker volumes" +# ansible.builtin.shell: docker volume ls -f name={{ portainer_stack_name }} --format '{{ '{{' }} .Name {{ '}}' }}' +# register: find_volumes +# changed_when: false -- name: "Stack {{ portainer_stack_name }} | Find docker volumes that need to be restored" - ansible.builtin.script: scripts/find-volumes-to-restore.py - environment: - EXISTING_VOLUMES: "{{ find_volumes.stdout_lines }}" - STACK_NAME: '{{ portainer_stack_name }}' - DOCKER_COMPOSE_DIR: '{{ directories.docker_compose_directory }}' - args: - executable: python3 - register: python_output - changed_when: false +#- name: "Stack {{ portainer_stack_name }} | Find docker volumes that need to be restored" +# ansible.builtin.script: scripts/find-volumes-to-restore.py +# environment: +# EXISTING_VOLUMES: "{{ find_volumes.stdout_lines }}" +# STACK_NAME: '{{ portainer_stack_name }}' +# DOCKER_COMPOSE_DIR: '{{ directories.docker_compose_directory }}' +# args: +# executable: python3 +# register: python_output +# changed_when: false -- name: "Stack {{ portainer_stack_name }} | Build list of volumes to restore." - ansible.builtin.set_fact: - restore_volumes: "{{ restore_volumes | default([]) + [{'volume_name':item}] }}" - with_items: "{{ python_output.stdout_lines | list }}" +#- name: "Stack {{ portainer_stack_name }} | Build list of volumes to restore." +# ansible.builtin.set_fact: +# restore_volumes: "{{ restore_volumes | default([]) + [{'volume_name':item}] }}" +# with_items: "{{ python_output.stdout_lines | list }}" -- name: "Stack {{ portainer_stack_name }} | Restore any missing volumes from S3" - ansible.builtin.include_role: - name: chatton.docker_backup.docker_s3_volume_restore - when: restore_volumes is defined - vars: - docker_backup_restore_force: false - docker_backup_restore_latest_s3_key: true - docker_backup_s3_restores: "{{ restore_volumes }}" +#- name: "Stack {{ portainer_stack_name }} | Restore any missing volumes from S3" +# ansible.builtin.include_role: +# name: chatton.docker_backup.docker_s3_volume_restore +# when: restore_volumes is defined +# vars: +# docker_backup_restore_force: false +# docker_backup_restore_latest_s3_key: true +# docker_backup_s3_restores: "{{ restore_volumes }}" - name: "Stack {{ portainer_stack_name }} | Update Portainer." chatton.portainer.portainer_stack: diff --git a/roles/setup_hosted_services/files/dashboards/dashy-config.yml b/roles/setup_hosted_services/files/dashboards/dashy-config.yml index 23e07fd..76096ef 100644 --- a/roles/setup_hosted_services/files/dashboards/dashy-config.yml +++ b/roles/setup_hosted_services/files/dashboards/dashy-config.yml @@ -29,6 +29,24 @@ sections: - title: Glances icon: hl-glances url: http://qnap:8083 + - title: Pihole + icon: hl-pihole + url: http://qnap:85/admin + - name: Snunmu Dashboards + widgets: + - type: gl-disk-space + options: + hostname: http://snunmu:8083 + items: + - title: Dash Dot + icon: hl-dashdot + url: http://snunmu:3010 + - title: Glances + icon: hl-glances + url: http://snunmu:8083 + - title: Pihole + icon: hl-pihole + url: http://snunmu:85/admin - name: Media Stack items: - title: Plex @@ -64,7 +82,7 @@ sections: - title: Linkding description: Manager photos icon: hl-linkding - url: http://qnap:9090 + url: http://snunmu:9090 - title: Nextcloud icon: hl-nextcloud url: http://qnap:8081 diff --git a/roles/setup_hosted_services/tasks/main.yml b/roles/setup_hosted_services/tasks/main.yml index 38ce430..546a818 100644 --- a/roles/setup_hosted_services/tasks/main.yml +++ b/roles/setup_hosted_services/tasks/main.yml @@ -29,6 +29,7 @@ owner: root group: root mode: 0440 + ignore_errors: true notify: - restart-dashy @@ -69,7 +70,7 @@ name: backup docker volumes (nightly) weekday: "*" minute: "0" - hour: "4" + hour: "{{ cron_hour }}" user: "{{ homelab_user }}" job: > {{ ansible_pull_path }} diff --git a/roles/setup_hosted_services/templates/dashboards.j2 b/roles/setup_hosted_services/templates/dashboards.j2 index ecee342..d800345 100644 --- a/roles/setup_hosted_services/templates/dashboards.j2 +++ b/roles/setup_hosted_services/templates/dashboards.j2 @@ -1,6 +1,7 @@ --- version: '3.5' services: +{% if template_vars.dashdot %} dash-dot: container_name: dashdot image: mauricenino/dashdot:latest @@ -10,7 +11,8 @@ services: - '3010:3001' volumes: - /:/mnt/host:ro - +{% endif %} +{% if template_vars.dashy %} dashy: container_name: dashy image: lissy93/dashy @@ -35,7 +37,8 @@ services: timeout: 10s retries: 3 start_period: 40s - +{% endif %} +{% if template_vars.glances %} glances: image: nicolargo/glances:latest-alpine restart: always @@ -46,3 +49,4 @@ services: - /var/run/docker.sock:/var/run/docker.sock environment: - "GLANCES_OPT=-w" +{% endif %} diff --git a/roles/setup_hosted_services/templates/pihole.j2 b/roles/setup_hosted_services/templates/pihole.j2 new file mode 100644 index 0000000..48d25c6 --- /dev/null +++ b/roles/setup_hosted_services/templates/pihole.j2 @@ -0,0 +1,21 @@ +--- +version: "3" +services: + pihole: + container_name: pihole + image: "pihole/pihole:2022.09.2" + ports: + - "53:53/tcp" + - "53:53/udp" + - "85:80/tcp" + environment: + WEBPASSWORD: '{{ pihole_web_password }}' + DNSMASQ_LISTENING: "all" + volumes: + - '{{ inventory_hostname_short }}_app:/etc/pihole' + - '{{ inventory_hostname_short }}_dns:/etc/dnsmasq.d' + restart: unless-stopped + +volumes: + "{{ inventory_hostname_short }}_app": + "{{ inventory_hostname_short }}_dns": diff --git a/vault_vars/qnap-vault.yml b/vault_vars/qnap-vault.yml index cb93ada..e4f2de9 100644 --- a/vault_vars/qnap-vault.yml +++ b/vault_vars/qnap-vault.yml @@ -1,53 +1,56 @@ $ANSIBLE_VAULT;1.1;AES256 -65643763356433316330636633643166346433393961353439313166383463363438373765656365 -3831643632336537663761363438656264376632663732630a363132303066376262656132643839 -66633061633861383139343235376237336266383666373532333433306336396537643363633238 -6633373336633139350a303762356261333830323934663565393630336139393032643239633932 -65373337663435333031656632366263303235393561613738376634316639303831343638386365 -61623132663331643833343864656332613532333833626532623037623734633039663931376466 -62326137373563356261363735616435656261633335383137393562386132393237356366343038 -62343561653362646635373766313537326136656537366631643662613565323934653062353032 -38616638626465303666626466303064336564653138663731336435616531633631333433353730 -39313666373938333765373535653233373766316337386361663233393438623334386535386662 -39383261633964326433363538666561373762643837656534366233313932376135363766616266 -39353831306536633133383064623230376238326336303932353535336239373761313062656435 -37383833373434656534623763613430663237383033656538653735646635303265306363316361 -35393132303137666562396535366132653532393039633138653736363631306135613336623139 -37663839613164626332366131303335636534626132313238316633326635666134336665323233 -30333436323830383737356566363364626339313438323963336130613964376566376135633566 -38313464313437333931386633316265613261643532656262366566633437373963376136323038 -62313231393134643464316565623765656436643964313865373732343561356530316536323631 -65626162393461343634383931313239353866633565653830333661336263323638333364623166 -64396532643861613539636263393239623938353239616432333263306639333563616138386631 -61373763326330623064323461336330653762316266303165313434366531663638666263653262 -35343834343361613562373831383565303364613631666432613436656564396536633334353338 -63353633326631386333663564643234323266623237323064663563633961376335396161306662 -38616538326338353362333364653339626464323432656466616337326662626439313537396330 -61303066376666643035633037623736373337316639623532306363356362393163393234346235 -63346366323830383365666466333064303533386530646637633038623766306161353933393635 -64366336303762623662373964366264373662616637373133343864636666616337303638353831 -31386166633864343938396465366530346539303932393239613237333863363034306364373230 -36363563356136623232616539383934336163333563663033613963646431336663613966393635 -34376334633035376333373366653262313333653966643134393265346131336565646132303166 -39373232623565663438353861306463333034393463383732326163376231343364313466623137 -38366264366530613563386132636135626530323339303531316432313234366466303939323565 -62623235356334316336336335613436373434356133643263303366323537353364326633383465 -65316435343530303365396664613034323038303866653434643562346531663635323032646136 -31623539396265653434646133313635636437646261636134643333386635323266356432346165 -37646136616233346138386639326666643237303930663630643733333563623533313866306532 -65633132613739353434366564366433353034336466323265666432356563646430396165643133 -31336361323938653031393462653533666332626439336135393262663633386162306566383232 -30396533613866623338373366643665346162666265633765333062356235363331363737333535 -30343036663130633031666533623335613234353933386635663866343662333931396363356162 -64646431373936373935383066653561383866353531303937356361616664363237633238376235 -66313962313965663931393363363639343061613161353038343933326433386264656563393838 -31656439316432626631346265646262333235666362666639303863633166333331623064323835 -64613362376362353537383035646164313862333836386132646239373734626538366163663966 -30616433346662626664653132396638383966303065626432316665396463663935343731363033 -61323036623239616136636235666463643433646632396465633234393438623938313261376364 -32623463633036653339316138323130623634626266373666303935353332356564363835343662 -64333134353234383935306439393031363833353237366131326265646433383862336163623138 -34316333396135313863393139383462616130393939366337353737636231656436316463666265 -65376166366338373437336436303835333831663062663039313934613732313563346538643565 -32336131306265633462343333623066656466313435303961313565333130613732373366313639 -66393163396365666431 +36366133663433613231613961343232323738393961386166343066373337333633313564653266 +3465326438343038323338653835363837323863663735370a333936383738303331366431636462 +35373964653835303530336139303163383162363164313333356535666339393231633461313162 +3861663065633736620a306437666563616266386439373464643635396632633164623066613362 +63666666306634326638346466646635353333623730303136353761363439396631346665643134 +61656133323461346639623534633331623533663430643739346261623766343933643937393263 +65313431613064333361363165653632343462636262396435306666326136313139313837313539 +34313939633538613661393065656438306537343863653135316530636133373933363638316332 +64333738633332313233383833393932613535613037373637393236383835333363626332353763 +31316163343633363463386465616439313661663236663734623438653262643831613932646561 +30633034633364616338343463366233376663613536623865663036353333656366393134396332 +39666666343963373539656665306366643736393962323138333636656366623666396638643662 +32666533356661306137663037663563393634333166353938623434663563366466656463666334 +39373831303835636331636235616361323435646434653638663561353161633037396634353863 +66333065386439376537653530323431343834346636663564333835373635356233396334356438 +61383537653533326565393536623639636434323934376537343030643364333134353731396438 +31333766383063353630363465323330376139646537356165666361323036376535663433643865 +38353461393937313833623263356134313935666639333032653434333739393438656561313138 +64366434376637353139376566623764393562663134353330313162656239653064363136333363 +30383266646331363338326633383263643739323031393766653833356130353366356535373361 +36633261386336316361653433663637373034623963646561323132613066653337313031326563 +63313962343730613436323966323562633563323664656234303064346666303164623831356561 +31613664303331633830393165383135373563626261363930363362336131623965373136396634 +38316232653739393439386133306338626462343566633330363336363238346562323561373237 +66653831396135653032366637323839316533323661633264656432663039303737336535376635 +32353064613964303738393936373561626661316662336634663637383465646337633964636364 +30336166393463343664343062366532656365636634313766613766313132623962376665306439 +31386133623734626338326165623762396338386134346364373336616139616330386166303433 +32373338326366623237346561396663373839313833666238393937333937396231326465653939 +35333439323439626332616461363165313732366434333462373464343338356230353630636139 +61323837376134343061353666356531316565616539646162313964336334653237626431643034 +35386664383030373037333537383437336234646136643233366339626266666233643563333965 +30336364613566303634653530386136656239383763636338346436653833653434306438346534 +65393131306365663837366365656335643763616162643064356561386635383064353339626335 +31393438373137363937346236343035633363316661663637393661613066343862313464306165 +30306561326131383336346263366637396362646138313136633466333833663033363961633466 +31343439353863343264306238633064623763343863343564383163653639303164363461346437 +33616433656566653065343932386466343436313531363263306637383235353666666233363666 +62656537303237323034613731343561323766613336363064346334366263663737646132393130 +36323466323262323937396137366161383066323537353136323832633066383866336365316535 +37653530323365656633643837666538316537323033613431333839303133326337393233643238 +30393630643439653733373733393330366466386564646431643232376234373734316637656130 +34303262633331643736396635663232653332366366616636346539666430313266363736303036 +66376530323538323439313834326262343234633361626130303535313162306365616265323131 +32353663396434636134663033396264383061323637356438363362626332363163393734386531 +62666365633335303264393230303730613731376433613462306464393836626434613961656430 +31393761316666656637633666316335356433643966363565633934393133653166333731333930 +31653430656365376133643964336237353064636533313135313965333738386365373638623138 +65313432386463336338356134373564633938376233343361623932626264623938373333616536 +64333361376165396665373163316666383830653262343732306536623432353065626532663731 +63623434613866346532396564303634653565386661363838366339333338353633363437323636 +37346331323836333561666165393661353730646164636233343362333334626133333934616462 +66303532636436646632626632326632353732633833653330326632666538363334303965373262 +38343639303730316235313538333636313438346130386535313334373434333239393366383661 +373434663138393331353436313837313765