Skip to content

Instantly share code, notes, and snippets.

@bendews
Created April 5, 2018 09:17
Show Gist options
  • Select an option

  • Save bendews/e09edfc60e581ec4c686c4b70297f543 to your computer and use it in GitHub Desktop.

Select an option

Save bendews/e09edfc60e581ec4c686c4b70297f543 to your computer and use it in GitHub Desktop.

Revisions

  1. bendews revised this gist Apr 5, 2018. No changes.
  2. bendews created this gist Apr 5, 2018.
    1 change: 1 addition & 0 deletions pihole-dnsmasq-cloudflared.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    server=127.0.0.1#5053
    11 changes: 11 additions & 0 deletions pihole-setupVars.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    !!!!!!!!!!!!!!!
    NOTE THIS IS A BASIC EXAMPLE OF A CONFIGURATION.
    YOU SHOULD COPY YOUR EXISTING CONFIGURATION FROM /etc/pihole/setupVars.conf
    THIS CAN BE USED AS A "STARTER" CONFIGURATION FOR FRESH INSTALLS BUT WILL OVERWRITE ANY EXISTING CONFIG
    !!!!!!!!!!!!!!!
    PIHOLE_INTERFACE=ens192
    IPV4_ADDRESS=10.1.1.250/24
    IPV6_ADDRESS=
    QUERY_LOGGING=true
    INSTALL_WEB=true
    LIGHTTPD_ENABLED=1
    54 changes: 54 additions & 0 deletions pihole.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    - hosts: pihole
    become: yes
    tasks:

    - include_role:
    name: bendews.cloudflared
    vars:
    cloudflared_port: 5053

    - name: create pihole directory
    file:
    path: /etc/pihole
    state: directory

    - name: copy pihole conf
    copy:
    src: pihole-setupVars.conf
    dest: /etc/pihole/setupVars.conf
    register: pihole_config

    - stat:
    path: /usr/local/bin/pihole
    register: pihole_binary

    - set_fact:
    pihole_installed: "{{ pihole_binary.stat.exists | default(false) }}"

    - name: download install script
    get_url:
    url: https://raw.githubusercontent.com/pi-hole/pi-hole/master/automated%20install/basic-install.sh
    dest: ~/pihole-install.sh
    mode: u+rwx
    when: not pihole_installed

    - name: run install script
    shell: ~/pihole-install.sh --unattended
    when: not pihole_installed

    - name: copy dnsmasq conf
    copy:
    src: pihole-dnsmasq-cloudflared.conf
    dest: /etc/dnsmasq.d/50-cloudflared.conf
    register: dnsmasq_config

    - name: this should be done via a handler but is simplified for this gist
    set_fact:
    restart_dnsmasq: "{{ true if (pihole_config is changed or dnsmasq_config is changed) else false }}"

    - name: restart dnsmasq service (this should be done via a handler but is simplified for this gist)
    service:
    name: dnsmasq
    enabled: true
    state: restarted
    when: restart_dnsmasq