diff --git a/.ansible-lint b/.ansible-lint new file mode 100644 index 0000000..0e46fff --- /dev/null +++ b/.ansible-lint @@ -0,0 +1,10 @@ +--- +exclude_paths: + - .cache/ + - .github/ + - .git/ + +use_default_rules: true + +mock_roles: + - pi_hole diff --git a/.github/workflows/linter.yaml b/.github/workflows/linter.yaml new file mode 100644 index 0000000..d980002 --- /dev/null +++ b/.github/workflows/linter.yaml @@ -0,0 +1,18 @@ +name: linter + +on: + pull_request: {} + +jobs: + lint: + runs-on: ubuntu-20.04 + container: + image: quay.io/ansible/creator-ee:v0.4.2 + env: + image: ubuntu + version: 20.04 + steps: + - uses: actions/checkout@v2 + - name: molecule lint + run: | + molecule lint diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b9b0a08 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,52 @@ +name: release +on: + push: + branches: + - master + tags: + - "v*.*.*" + pull_request: + types: + - labeled + +jobs: + release: + if: github.event.action != 'labeled' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - id: bumpr + if: "!startsWith(github.ref, 'refs/tags/')" + uses: haya14busa/action-bumpr@v1 + + - uses: haya14busa/action-update-semver@v1 + if: "!steps.bumpr.outputs.skip" + with: + github_token: ${{ secrets.github_token }} + tag: ${{ steps.bumpr.outputs.next_version }} + + - id: tag + uses: haya14busa/action-cond@v1 + with: + cond: "${{ startsWith(github.ref, 'refs/tags/') }}" + if_true: ${{ github.ref }} + if_false: ${{ steps.bumpr.outputs.next_version }} + + - uses: actions/create-release@v1 + if: "steps.tag.outputs.value != ''" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ steps.tag.outputs.value }} + release_name: Release ${{ steps.tag.outputs.value }} + body: ${{ steps.bumpr.outputs.message }} + draft: false + prerelease: false + + release-check: + if: github.event.action == 'labeled' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: haya14busa/action-bumpr@v1 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..0e59750 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,41 @@ +name: test + +on: + pull_request: {} + +jobs: + test: + name: molecule test on ${{ matrix.image }} ${{ matrix.version }} + runs-on: ubuntu-20.04 + strategy: + fail-fast: false + matrix: + include: + - image: ubuntu + version: "18.04" + - image: ubuntu + version: "20.04" + - image: ubuntu + version: "21.10" + - image: debian + version: "9" + - image: debian + version: "10" + - image: debian + version: "11" + - image: fedora + version: "33" + - image: fedora + version: "34" + steps: + - uses: actions/checkout@v2 + - name: Setup Environment + run: | + python3 -m pip install --upgrade pip + python3 -m pip install molecule["docker"] ansible-lint yamllint + - name: molecule test + env: + image: ${{ matrix.image }} + version: ${{ matrix.version }} + run: | + molecule test diff --git a/.yamllint b/.yamllint new file mode 100755 index 0000000..0172006 --- /dev/null +++ b/.yamllint @@ -0,0 +1,27 @@ +--- +extends: default + +rules: + braces: + forbid: non-empty + min-spaces-inside: 1 + max-spaces-inside: 1 + min-spaces-inside-empty: 0 + max-spaces-inside-empty: 0 + brackets: + forbid: non-empty + min-spaces-inside: 1 + max-spaces-inside: 1 + min-spaces-inside-empty: 0 + max-spaces-inside-empty: 0 + indentation: + spaces: 2 + indent-sequences: consistent + line-length: + max: 160 + level: warning + allow-non-breakable-inline-mappings: true + new-lines: + type: unix +ignore: | + .github/ diff --git a/handlers/main.yml b/handlers/main.yml index a88fd3e..c324654 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,6 +1,6 @@ --- # handlers file for ansible-pi-hole/ - name: Restart pihole-FTL - sysvinit: + ansible.builtin.sysvinit: name: pihole-FTL state: restarted diff --git a/meta/main.yml b/meta/main.yml index 7507f56..e947d49 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -4,61 +4,31 @@ galaxy_info: role_name: pi_hole description: An Ansible Role to install Pi-Hole company: chubchubsancho + namespace: chubchubsancho - # If the issue tracker for your role is not on github, uncomment the - # next line and provide a value - # issue_tracker_url: http://example.com/issue/tracker - - # Some suggested licenses: - # - BSD (default) - # - MIT - # - GPLv2 - # - GPLv3 - # - Apache - # - CC-BY license: MIT - min_ansible_version: 2.4 - - # If this a Container Enabled role, provide the minimum Ansible Container version. - # min_ansible_container_version: + min_ansible_version: 2.7 - # Optionally specify the branch Galaxy will use when accessing the GitHub - # repo for this role. During role install, if no tags are available, - # Galaxy will use this branch. During import Galaxy will access files on - # this branch. If Travis integration is configured, only notifications for this - # branch will be accepted. Otherwise, in all cases, the repo's default branch - # (usually master) will be used. - # github_branch: - - # - # Provide a list of supported platforms, and for each platform a list of versions. - # If you don't wish to enumerate all versions for a particular platform, use 'all'. - # To view available platforms and versions (or releases), visit: - # https://galaxy.ansible.com/api/v1/platforms/ - # platforms: - name: Debian versions: - stretch - - jessie + - buster + - bullseye - name: Ubuntu versions: - - xenial - - yakkety - - name: EL + - bionic + - focal + - impish + - name: Fedora versions: - - 7 + - 33 + - 34 + galaxy_tags: - pihole - # List tags for your role here, one per line. A tag is a keyword that describes - # and categorizes the role. Users find roles by searching for tags. Be sure to - # remove the '[]' above, if you add tags to this list. - # - # NOTE: A tag is limited to a single word comprised of alphanumeric characters. - # Maximum 20 tags per role. + - dns dependencies: [] -# List your role dependencies here, one per line. Be sure to remove the '[]' above, -# if you add dependencies to this list. diff --git a/molecule/default/Dockerfile.j2 b/molecule/default/Dockerfile.j2 index ef40dc3..31d2900 100755 --- a/molecule/default/Dockerfile.j2 +++ b/molecule/default/Dockerfile.j2 @@ -18,3 +18,11 @@ RUN if [ $(command -v apt-get) ]; then apt-get update && DEBIAN_FRONTEND=noninte elif [ $(command -v dnf) ]; then dnf makecache && dnf --assumeyes install /usr/bin/python3 /usr/bin/python3-config /usr/bin/dnf-3 sudo bash iproute systemd systemd-sysv && dnf clean all; \ elif [ $(command -v yum) ]; then yum makecache fast && yum install -y /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl bash iproute systemd systemd-sysv && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; \ fi + +ENV ANSIBLE_USER=ansible DEPLOY_GROUP=deployer +RUN set -xe \ + && groupadd -r ${ANSIBLE_USER} \ + && groupadd -r ${DEPLOY_GROUP} \ + && useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \ + && usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \ + && echo "%${DEPLOY_GROUP} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 76cd868..48304ef 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -2,15 +2,15 @@ dependency: name: galaxy options: - role-files: requirements.yml + role-file: molecule/resources/requirements.yml + requirements-file: molecule/resources/requirements.yml driver: name: docker lint: | set -e - yamllint -c ./molecule/resources/rules/yamllint.yaml . - ansible-lint . + ansible-lint -q . platforms: - name: "instance" @@ -21,6 +21,11 @@ platforms: container: docker groups: - "default" + tmpfs: + - /run + - /tmp + volumes: + - /sys/fs/cgroup:/sys/fs/cgroup:ro provisioner: log: true @@ -39,17 +44,7 @@ provisioner: scenario: name: default - test_sequence: - - destroy - - dependency - - syntax - - create - - prepare - - converge - - idempotence - # - side_effect - # - verify - # - destroy verifier: - name: testinfra + name: ansible + enabled: False diff --git a/molecule/default/playbook.yml b/molecule/default/playbook.yml deleted file mode 100644 index e1163cd..0000000 --- a/molecule/default/playbook.yml +++ /dev/null @@ -1,7 +0,0 @@ ---- -- name: Converge - hosts: all - tasks: - - name: "install pi-hole" - import_role: - name: ansible-pi-hole diff --git a/molecule/default/tests/test_default.py b/molecule/default/tests/test_default.py index eedd64a..0829457 100755 --- a/molecule/default/tests/test_default.py +++ b/molecule/default/tests/test_default.py @@ -6,9 +6,7 @@ os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') -def test_hosts_file(host): - f = host.file('/etc/hosts') +def test_prerequisites_packages(host): + p = host.package('git') - assert f.exists - assert f.user == 'root' - assert f.group == 'root' + assert p.is_installed diff --git a/molecule/resources/playbook.yml b/molecule/resources/playbook.yml index e1163cd..e44e215 100755 --- a/molecule/resources/playbook.yml +++ b/molecule/resources/playbook.yml @@ -4,4 +4,4 @@ tasks: - name: "install pi-hole" import_role: - name: ansible-pi-hole + name: chubchubsancho.pi_hole diff --git a/molecule/resources/requirements.yml b/molecule/resources/requirements.yml new file mode 100644 index 0000000..cfc2bbc --- /dev/null +++ b/molecule/resources/requirements.yml @@ -0,0 +1,16 @@ +--- +collections: + - name: amazon.aws + - name: ansible.posix + - name: ansible.windows + - name: awx.awx + - name: azure.azcollection + - name: community.docker + - name: community.vmware + - name: containers.podman + - name: google.cloud + - name: kubernetes.core + - name: openstack.cloud + - name: ovirt.ovirt + - name: redhatinsights.insights + - name: theforeman.foreman diff --git a/molecule/resources/rules/ansible-lint.yaml b/molecule/resources/rules/ansible-lint.yaml deleted file mode 100755 index ed97d53..0000000 --- a/molecule/resources/rules/ansible-lint.yaml +++ /dev/null @@ -1 +0,0 @@ ---- diff --git a/molecule/resources/rules/yamllint.yaml b/molecule/resources/rules/yamllint.yaml deleted file mode 100755 index 0f25798..0000000 --- a/molecule/resources/rules/yamllint.yaml +++ /dev/null @@ -1,7 +0,0 @@ ---- -extends: default - -rules: - line-length: - max: 160 - level: warning diff --git a/tasks/configure.yml b/tasks/configure.yml index 06d7a73..c0772be 100644 --- a/tasks/configure.yml +++ b/tasks/configure.yml @@ -1,6 +1,6 @@ --- - name: configure pi-hole FTL - template: + ansible.builtin.template: src: etc/pihole/pihole-FTL.conf.j2 dest: /etc/pihole/pihole-FTL.conf mode: 0644 @@ -11,7 +11,7 @@ - configure - name: configure pi-hole local DNS records - template: + ansible.builtin.template: src: etc/pihole/custom.list.j2 dest: /etc/pihole/custom.list mode: 0644 diff --git a/tasks/debian-prerequisites.yml b/tasks/debian-prerequisites.yml index aca7624..1278afc 100644 --- a/tasks/debian-prerequisites.yml +++ b/tasks/debian-prerequisites.yml @@ -1,6 +1,6 @@ --- - name: "install packages" - apt: + ansible.builtin.apt: name: "{{ pi_hole_prerequisites }}" state: present update_cache: true diff --git a/tasks/install.yml b/tasks/install.yml index 5496fd9..2e782eb 100644 --- a/tasks/install.yml +++ b/tasks/install.yml @@ -1,6 +1,6 @@ --- - name: "check if pi-hole is already installed" - stat: + ansible.builtin.stat: path: "/opt/pihole" register: pihole_installed tags: @@ -9,7 +9,7 @@ - check - name: "create pihole config directory" - file: + ansible.builtin.file: name: /etc/pihole state: directory when: pihole_installed.stat.isdir is undefined @@ -19,7 +19,7 @@ - prepare - name: "copy pihole setupVars" - template: + ansible.builtin.template: src: etc/pihole/setupVars.conf.j2 dest: /etc/pihole/setupVars.conf mode: 0644 @@ -30,7 +30,7 @@ - prepare - name: "clone pihole repository revision '{{ pi_hole_version }}'" - git: + ansible.builtin.git: repo: "{{ pi_hole_repo }}" clone: true depth: 20 @@ -44,7 +44,7 @@ - name: "install pihole" become: true - command: bash basic-install.sh --unattended + ansible.builtin.command: bash basic-install.sh --unattended args: chdir: "{{ pi_hole_install_dir }}/automated install" creates: installed.txt diff --git a/tasks/redhat-prerequisites.yml b/tasks/redhat-prerequisites.yml index 7f51547..c5897ab 100644 --- a/tasks/redhat-prerequisites.yml +++ b/tasks/redhat-prerequisites.yml @@ -1,6 +1,6 @@ --- - name: "install packages" - yum: + ansible.builtin.yum: name: "{{ pi_hole_prerequisites }}" state: present update_cache: true diff --git a/templates/etc/pihole/setupVars.conf.j2 b/templates/etc/pihole/setupVars.conf.j2 index 8d28856..5e22426 100644 --- a/templates/etc/pihole/setupVars.conf.j2 +++ b/templates/etc/pihole/setupVars.conf.j2 @@ -32,7 +32,7 @@ REV_SERVER_TARGET={{ pi_hole_rev_server_target }} {% if pi_hole_rev_server_cidr is defined %} REV_SERVER_CIDR={{ pi_hole_rev_server_cidr }} {% endif %} -{% if pi_hole_dhcp_active %} +{% if pi_hole_dhcp_active is defined and pi_hole_dhcp_active %} DHCP_ACTIVE=true DHCP_START={{ pi_hole_dhcp_start }} DHCP_END={{ pi_hole_dhcp_end }}