From a0c0c11c1bcf3d3cf33e76d37d3015373e676c29 Mon Sep 17 00:00:00 2001 From: janic Date: Mon, 6 Dec 2021 14:00:39 +0100 Subject: [PATCH] pihole silent install --- LICENSE | 2 +- additional/handler-pihole.yaml | 4 ++++ additional/pihole_default.yaml | 0 additional/pre_tasks-pihole.yaml | 12 ++++++++++++ hosts | 6 ++++++ pihole-playbook.yaml | 25 +++++++++++++++++++++++++ pihole-test.yaml | 7 +++++++ templates/pihole-setupVars.conf.j2 | 20 ++++++++++++++++++++ 8 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 additional/handler-pihole.yaml create mode 100644 additional/pihole_default.yaml create mode 100644 additional/pre_tasks-pihole.yaml create mode 100644 hosts create mode 100644 pihole-playbook.yaml create mode 100644 pihole-test.yaml create mode 100644 templates/pihole-setupVars.conf.j2 diff --git a/LICENSE b/LICENSE index 137069b..ac2238b 100644 --- a/LICENSE +++ b/LICENSE @@ -58,7 +58,7 @@ APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. -Copyright [yyyy] [name of copyright owner] +Copyright 2021 Janic Voser Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/additional/handler-pihole.yaml b/additional/handler-pihole.yaml new file mode 100644 index 0000000..411907b --- /dev/null +++ b/additional/handler-pihole.yaml @@ -0,0 +1,4 @@ +--- +- name: Install Pihole + shell: curl -sSL https://install.pi-hole.net | bash +... \ No newline at end of file diff --git a/additional/pihole_default.yaml b/additional/pihole_default.yaml new file mode 100644 index 0000000..e69de29 diff --git a/additional/pre_tasks-pihole.yaml b/additional/pre_tasks-pihole.yaml new file mode 100644 index 0000000..d497fca --- /dev/null +++ b/additional/pre_tasks-pihole.yaml @@ -0,0 +1,12 @@ + - name: Load variable files + include_vars: "{{ item }}" + with_first_found: + - "pihole_{{ ansible_os_family }}.yaml" + - "pihole_default.yaml" + - name: Update APT-cache if Debianbased + apt: update_cache=yes cache_valid_time=3600 + when: ansible_os_family == 'Debian' + - name: Install curl + package: + name: curl + state: latest \ No newline at end of file diff --git a/hosts b/hosts new file mode 100644 index 0000000..d804ec9 --- /dev/null +++ b/hosts @@ -0,0 +1,6 @@ +[lxc-pihole] +pihole01.voser.local ansible_host=172.22.0.11 +pihole02.voser.local ansible_host=172.22.0.12 +[lxc-pihole:vars] +ansible_user=root +ansible_port=22 diff --git a/pihole-playbook.yaml b/pihole-playbook.yaml new file mode 100644 index 0000000..5b4e4ff --- /dev/null +++ b/pihole-playbook.yaml @@ -0,0 +1,25 @@ +--- +- name: pihole-playbook + hosts: lxc-pihole + gather_facts: yes + + handlers: + - import_tasks: additional/handler-pihole.yaml + pre_tasks: + - import_tasks: additional/pre_tasks-pihole.yaml + + tasks: + - name: Create /etc/pihole + file: + path: /etc/pihole + state: directory + mode: '0644' + - name: Create Config + template: + src: templates/pihole-setupVars.conf.j2 + dest: /etc/pihole/setupVars.conf + register: template + - name: pihole install + shell: curl -L https://install.pi-hole.net | bash /dev/stdin --unattended + when: template.changed +... \ No newline at end of file diff --git a/pihole-test.yaml b/pihole-test.yaml new file mode 100644 index 0000000..cef4432 --- /dev/null +++ b/pihole-test.yaml @@ -0,0 +1,7 @@ +--- +- name: test + hosts: lxc-pihole + + tasks: + - debug: var=ansible_all_ipv4_addresses + - debug: var=hostvars[inventory_hostname]['ansible_default_ipv4']['address'] \ No newline at end of file diff --git a/templates/pihole-setupVars.conf.j2 b/templates/pihole-setupVars.conf.j2 new file mode 100644 index 0000000..79b392c --- /dev/null +++ b/templates/pihole-setupVars.conf.j2 @@ -0,0 +1,20 @@ +WEBPASSWORD=a215bae8b5ec659b0980a76dlkds09644731cd439cab41494447a8705c22b3aa41c +PIHOLE_INTERFACE=eth0 +IPV4_ADDRESS={{ ansible_eth0.ipv4.address }}/22 +IPV6_ADDRESS= +QUERY_LOGGING=true +INSTALL_WEB=true +DNSMASQ_LISTENING=single +PIHOLE_DNS_1=1.1.1.1 +PIHOLE_DNS_2=1.0.0.1 +PIHOLE_DNS_3=9.9.9.9 +PIHOLE_DNS_4=149.112.112.11 +DNS_FQDN_REQUIRED=true +DNS_BOGUS_PRIV=true +DNSSEC=true +TEMPERATUREUNIT=C +WEBUIBOXEDLAYOUT=traditional +API_EXCLUDE_DOMAINS= +API_EXCLUDE_CLIENTS= +API_QUERY_LOG_SHOW=all +API_PRIVACY_MODE=false \ No newline at end of file