Skip to content

Commit

Permalink
Resolve ansible-lint name casing and no-change-when warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
r-pufky committed Mar 18, 2024
1 parent 520bf1c commit ab12e09
Show file tree
Hide file tree
Showing 13 changed files with 62 additions and 64 deletions.
2 changes: 0 additions & 2 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
---
skip_list:
- unnamed-task # unnamed tasks are used as includes.
- package-latest # allow 'latest' packages.
warn_list:
- experimental
- no-changed-when
exclude_paths:
- .github/workflows/
2 changes: 1 addition & 1 deletion defaults/main/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pihole_update_enable: false

# Disable role behavior change warnings. Default: False.
# When potentially role-breaking changes have been made to the role and config
# must be re-evaulated to apply the role safely. This will present a user
# must be re-evaluated to apply the role safely. This will present a user
# message that will pause the role and eventually timeout. The default value
# will change on releases based on role changes.
#
Expand Down
2 changes: 1 addition & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@

# pihole restartdns restarts all required pihole services.
# Reference: https://discourse.pi-hole.net/t/the-pihole-command-with-examples/738
- name: 'restart pihole dns'
- name: 'Restart pihole dns' # noqa no-changed-when
ansible.builtin.command: '/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended'
8 changes: 4 additions & 4 deletions tasks/backup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
# * https://docs.pi-hole.net/core/pihole-command/#teleport

# Teleporter dump created with execution timestamp. backup & standardize.
- name: 'backup | create backup' # noqa no-changed-when always execute
- name: 'Backup | create backup' # noqa no-changed-when always execute
ansible.builtin.shell: |
cd /root &&
pihole -a -t &&
find /root -type f -name 'pi-hole-*.tar.gz' -exec mv {} /root/pihole.tar.gz \;
args:
warn: false

- name: 'backup | retrieve backup'
- name: 'Backup | retrieve backup'
ansible.builtin.fetch:
src: '/root/pihole.tar.gz'
dest: '{{ pihole_local_backup }}'
flat: true

- name: 'backup | ENCRYPTION NOTICE'
- name: 'Backup | ENCRYPTION NOTICE'
ansible.builtin.debug:
msg: |
BE SURE TO ENCRYPT BEFORE COMMITTING CHANGES.
ansible-vault encrypt '{{ pihole_local_backup }}'
- name: 'backup | cleanup'
- name: 'Backup | cleanup'
ansible.builtin.file:
path: '{{ item }}'
state: 'absent'
Expand Down
4 changes: 2 additions & 2 deletions tasks/db/add_clients.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
# Reference:
# * https://docs.pi-hole.net/database/

- name: 'db | add client {{ client.id }}'
- name: 'DB | add client {{ client.id }}' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_client_insert }} ({{ client.id }}, \"{{ client.ip }}\", \"{{ client.comment }}\")"'
become: true

- name: 'db | remove client from default group - {{ client.id }}'
- name: 'DB | remove client from default group - {{ client.id }}' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_client_groups_delete_default }} {{ client.id }}"'
become: true
when: |
Expand Down
4 changes: 2 additions & 2 deletions tasks/db/clear_databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# application at the expense of recreating the DB's and downloading/rebuilding
# blocklists each run.

- name: 'clear databases | remove databases'
- name: 'DB | clear databases | remove databases'
ansible.builtin.file:
path: '/etc/pihole/{{ item }}'
state: 'absent'
loop:
- 'gravity.db'
- 'pihole-FTL.db'

- name: 'clear databases | regenerate databases'
- name: 'DB | clear databases | regenerate databases'
ansible.builtin.command: '/etc/.pihole/automated\ install/basic-install.sh --reconfigure --unattended'
changed_when: false
10 changes: 5 additions & 5 deletions tasks/db/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@
# * https://docs.pi-hole.net/guides/misc/whitelist-blacklist/
# * https://docs.pi-hole.net/core/pihole-command/#whitelisting-blacklisting-and-regex

- name: 'cli | check {{ domain.domain }}'
- name: 'DB CLI | check {{ domain.domain }}' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_binary }} -q -exact "{{ domain.domain }}"'
changed_when: false
become: true
register: _pihole_cli_domain_exact_check

- name: 'cli | remove from whitelist - {{ domain.domain }}'
- name: 'DB CLI | remove from whitelist - {{ domain.domain }}' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_binary }} -w -d "{{ domain.domain }}"'
become: true
when:
('whitelist' in _pihole_cli_domain_exact_check.stdout) and
not domain.enabled

- name: 'cli | remove from blacklist - {{ domain.domain }}'
- name: 'DB CLI | remove from blacklist - {{ domain.domain }}' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_binary }} -b -d "{{ domain.domain }}"'
become: true
when:
('blacklist' in _pihole_cli_domain_exact_check.stdout) and
not domain.enabled

- name: 'cli | add to whitelist - {{ domain.domain }}'
- name: 'DB CLI | add to whitelist - {{ domain.domain }}' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_binary }} -w "{{ domain.domain }}" --comment "{{ domain.comment }}"'
become: true
when:
Expand All @@ -53,7 +53,7 @@
(domain.type == 0 or domain.type == 2) and
domain.enabled

- name: 'cli | add to blacklist - {{ domain.domain }}'
- name: 'DB CLI | add to blacklist - {{ domain.domain }}' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_binary }} -b "{{ domain.domain }}" --comment "{{ domain.comment }}"'
become: true
when:
Expand Down
18 changes: 9 additions & 9 deletions tasks/db/db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
# Reference:
# * https://docs.pi-hole.net/database/

- name: 'include | clear_databases'
- name: 'DB | include clear_databases'
ansible.builtin.include_tasks: clear_databases.yml
when: pihole_idempotent

- name: 'db | add adlist source'
- name: 'DB | add adlist source' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_ad_insert }} ({{ item.id }}, \"{{ item.address }}\", {{ item.enabled | int }}, \"{{ item.comment }}\")"'
become: true
loop: '{{ pihole_ad_sources }}'
when: pihole_ad_sources|length > 0

- name: 'db | defer to cli for domain blocklist management'
- name: 'DB | defer to cli for domain blocklist management'
ansible.builtin.include_tasks: cli.yml
loop: '{{ pihole_domain_blocklists }}'
loop_control:
loop_var: domain
when: pihole_use_cli and pihole_domain_blocklists|length > 0

- name: 'db | add domain blocklist'
- name: 'DB | add domain blocklist' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_domain_insert }} ({{ item.id }}, {{ item.type }}, \"{{ item.domain }}\", {{ item.enabled | int }}, \"{{ item.comment }}\")"'
become: true
loop: '{{ pihole_domain_blocklists }}'
Expand All @@ -42,31 +42,31 @@
loop_control:
loop_var: client

- name: 'db | add groups'
- name: 'DB | add groups' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_groups_insert }} ({{ item.id }}, {{ item.enabled | int }}, \"{{ item.name }}\", \"{{ item.description }}\")"'
become: true
loop: '{{ pihole_groups }}'
when: pihole_groups|length > 0

- name: 'db | add groups ad blocklist'
- name: 'DB | add groups ad blocklist' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_ad_groups_insert }} ({{ item.adlist_id }}, {{ item.group_id }})"'
become: true
loop: '{{ pihole_ad_groups_blocklist }}'
when: pihole_ad_groups_blocklist|length > 0

- name: 'db | add groups client blocklist'
- name: 'DB | add groups client blocklist' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_client_groups_insert }} ({{ item.client_id }}, {{ item.group_id }})"'
become: true
loop: '{{ pihole_client_groups_blocklist }}'
when: pihole_client_groups_blocklist|length > 0

- name: 'db | add groups domain blocklist'
- name: 'DB | add groups domain blocklist' # noqa no-changed-when
ansible.builtin.command: '{{ pihole_default_sqlite3 }} "{{ pihole_default_domain_groups_insert }} ({{ item.domainlist_id }}, {{ item.group_id }})"'
become: true
loop: '{{ pihole_domain_groups_blocklist }}'
when: pihole_domain_groups_blocklist|length > 0

- name: 'db | update gravity adlists'
- name: 'DB | update gravity adlists' # noqa no-changed-when
ansible.builtin.command: 'pihole -g'
when: >
not pihole_installed or
Expand Down
18 changes: 9 additions & 9 deletions tasks/deps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,48 @@
###############################################################################
# Manage dependency installation for all platforms and VM's.

- name: 'dependencies | debian'
- name: 'Dependencies | debian'

Check failure on line 7 in tasks/deps.yml

View workflow job for this annotation

GitHub Actions / build

key-order[task]

You can improve the task key order to: name, when, block
block:
- name: 'dependencies | install debian docker packages'
- name: 'Dependencies | install debian docker packages'
ansible.builtin.apt:
name: '{{ pihole_default_packages_debian_docker }}'
state: 'latest'
update_cache: true
when: pihole_docker

- name: 'dependencies | install debian packages'
- name: 'Dependencies | install debian packages'
ansible.builtin.apt:
name: '{{ pihole_default_packages_debian }}'
state: 'latest'
update_cache: true
when: ansible_distribution == 'Debian'

- name: 'dependencies | ubuntu'
- name: 'Dependencies | ubuntu'

Check failure on line 23 in tasks/deps.yml

View workflow job for this annotation

GitHub Actions / build

key-order[task]

You can improve the task key order to: name, when, block
block:
- name: 'dependencies | install ubuntu docker packages'
- name: 'Dependencies | install ubuntu docker packages'
ansible.builtin.apt:
name: '{{ pihole_default_packages_ubuntu_docker }}'
state: 'latest'
update_cache: true
when: pihole_docker

- name: 'dependencies | install ubuntu packages'
- name: 'Dependencies | install ubuntu packages'
ansible.builtin.apt:
name: '{{ pihole_default_packages_ubuntu }}'
state: 'latest'
update_cache: true
when: ansible_distribution == 'Ubuntu'

- name: 'dependencies | redhat'
- name: 'Dependencies | redhat'

Check failure on line 39 in tasks/deps.yml

View workflow job for this annotation

GitHub Actions / build

key-order[task]

You can improve the task key order to: name, when, block
block:
- name: 'dependencies | install redhat docker packages'
- name: 'Dependencies | install redhat docker packages'
ansible.builtin.apt:
name: '{{ pihole_default_packages_redhat_docker }}'
state: 'latest'
update_cache: true
when: pihole_docker

- name: 'dependencies | install redhat packages'
- name: 'Dependencies | install redhat packages'
ansible.builtin.dnf:
name: '{{ pihole_default_packages_redhat }}'
state: 'latest'
Expand Down
22 changes: 11 additions & 11 deletions tasks/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# * https://gist.github.com/bendews/e09edfc60e581ec4c686c4b70297f543

# Pi-Hole will set correct permissions on install and startup.
- name: 'install | create /etc/pihole'
- name: 'Install | create /etc/pihole'
ansible.builtin.file:
path: '/etc/pihole'
mode: '0775'
state: 'directory'

- name: 'install | set deployment config'
- name: 'Install | set deployment config'
ansible.builtin.template:
src: 'setupVars.conf.j2'
dest: '/etc/pihole/setupVars.conf'
Expand All @@ -30,37 +30,37 @@
mode: '0644'
notify: 'restart pihole dns'

- name: 'install | set binary location'
- name: 'Install | set binary location'
ansible.builtin.stat:
path: '/usr/local/bin/pihole'
register: _pihole_binary

- name: 'install | determine if pihole is installed'
- name: 'Install | determine if pihole is installed'
ansible.builtin.set_fact:
pihole_installed: '{{ _pihole_binary.stat.exists | default(false) }}'

- name: 'install | fetching latest installer'
- name: 'Install | fetching latest installer'
ansible.builtin.get_url:
url: 'https://install.pi-hole.net'
dest: '/tmp/pihole-install.sh'
mode: 'u+rwx'
ignore_errors: '{{ ansible_check_mode }}'
when: not pihole_installed

- name: 'install | install'
- name: 'Install | install'

Check failure on line 50 in tasks/install.yml

View workflow job for this annotation

GitHub Actions / build

key-order[task]

You can improve the task key order to: name, when, block
block:
- name: 'install | standard install'
- name: 'Install | standard install'

Check failure on line 52 in tasks/install.yml

View workflow job for this annotation

GitHub Actions / build

no-changed-when

Commands should not change things if nothing needs doing.
ansible.builtin.command: '/tmp/pihole-install.sh --unattended'
when: not pihole_docker

- name: 'install | docker install'
- name: 'Install | docker install'

Check failure on line 56 in tasks/install.yml

View workflow job for this annotation

GitHub Actions / build

no-changed-when

Commands should not change things if nothing needs doing.
ansible.builtin.command: '/tmp/pihole-install.sh --unattended'
environment:
DEBIAN_FRONTEND: noninteractive
when: pihole_docker
when: not pihole_installed

- name: 'install | set FTL config'
- name: 'Install | set FTL config'
ansible.builtin.template:
src: 'pihole-FTL.conf.j2'
dest: '/etc/pihole/pihole-FTL.conf'
Expand All @@ -77,11 +77,11 @@
# Reference:
# * https://medium.com/@AbhijeetKasurde/ansible-generating-random-string-using-password-lookup-plugin-7cd3431a0d0
# * https://discourse.pi-hole.net/t/what-is-setupvars-conf-and-how-do-i-use-it/3533/5
- name: 'install | set random password (no install password set)'
- name: 'Install | set random password (no install password set)'

Check failure on line 80 in tasks/install.yml

View workflow job for this annotation

GitHub Actions / build

no-changed-when

Commands should not change things if nothing needs doing.
ansible.builtin.command: "pihole -a -p {{ lookup('password', '/dev/null chars=ascii_lowercase,digits length=8') }}"
when: pihole_webpassword|string|length == 0

- name: 'install | set password'
- name: 'Install | set password'

Check failure on line 84 in tasks/install.yml

View workflow job for this annotation

GitHub Actions / build

no-changed-when

Commands should not change things if nothing needs doing.
ansible.builtin.command: 'pihole -a -p {{ pihole_webpassword }}'
when: pihole_webpassword|string|length > 0
no_log: true # password
14 changes: 7 additions & 7 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Executes sub-tasks for applying the pihole role and presents any warning
# messages.

- name: 'main | WARNING ROLE BEHAVIOR CHANGED'
- name: 'Main | WARNING ROLE BEHAVIOR CHANGED'
ansible.builtin.debug:
msg: |
This role has breaking changes from previous versions.
Expand All @@ -19,19 +19,19 @@
Disable this message by setting 'pihole_disable_warning' to true.
when: not pihole_disable_warning

- name: 'config | pause until manually confirmed'
- name: 'Main | pause until manually confirmed'
ansible.builtin.pause:
echo: false
seconds: "{{ pihole_default_timeout }}"
when: not pihole_disable_warning

- name: 'import | deps'
- name: 'Main | deps'
ansible.builtin.import_tasks: deps.yml
- name: 'import | os_prep'
- name: 'Main | os_prep'
ansible.builtin.import_tasks: os_prep.yml
- name: 'import | install'
- name: 'Main | install'
ansible.builtin.import_tasks: install.yml
- name: 'import | db'
- name: 'Main | db'
ansible.builtin.import_tasks: db/db.yml
- name: 'import | update'
- name: 'Main | update'
ansible.builtin.import_tasks: update.yml
Loading

0 comments on commit ab12e09

Please sign in to comment.