Skip to content

Commit 60f1cca

Browse files
dguidoclaude
andauthored
Fix ansible-lint failures and code review sticky comments (#14885)
* Fix ansible-lint failures and improve linting configuration This PR eliminates all ansible-lint failures (9 → 0) and reduces warnings (25 → 20). The remaining warnings are yaml[line-length] which are intentionally in the warn_list. Changes: 1. GitHub workflow YAML compliance - Add document start markers (---) - Quote 'on:' key (YAML truthy value) 2. Replace ignore_errors with failed_when - privacy/clear_history.yml: Use failed_when: false instead of ignore_errors for tasks that may fail on clean systems 3. Use apt module instead of shell - privacy/auto_cleanup.yml: Replace apt-get shell command with proper apt module (autoclean: true) 4. Add changed_when to handlers and tasks - Handlers always run due to notifications, so changed_when: false is appropriate for read-only operations - Check commands that only read state get changed_when: false - Reboot task gets changed_when: true (it actually changes state) 5. Configure ansible-lint for project structure - Exclude CloudFormation templates (roles/cloud-*/files/) which use AWS-specific YAML tags (!Equals, !GetAtt) that ansible-lint cannot parse - Add mock_modules for custom modules in library/ directory that ansible-lint cannot auto-discover during static analysis See: ansible/ansible-lint#1353 6. Fix Jinja2 spacing - Remove extraneous whitespace in multi-line Jinja expressions - Fix spacing before closing parentheses References: - ansible-lint mock_modules: https://ansible.readthedocs.io/projects/lint/configuring/ - Custom module discovery issue: ansible/ansible-lint#1353 - Ansible local modules: https://docs.ansible.com/ansible/latest/dev_guide/developing_locally.html 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Workaround sticky comment bug in claude-code-action The use_sticky_comment feature is broken in claude-code-action v1. This adds instructions for Claude to minimize its old comments as OUTDATED before posting new reviews, preventing comment clutter. Also adds gh api to allowed tools for the GraphQL mutation. See: anthropics/claude-code-action#419 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> --------- Co-authored-by: Claude <[email protected]>
1 parent 9515e7e commit 60f1cca

File tree

10 files changed

+47
-20
lines changed

10 files changed

+47
-20
lines changed

.ansible-lint

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ exclude_paths:
66
- tests/
77
- files/cloud-init/ # Cloud-init files have special format requirements
88
- playbooks/ # These are task files included by other playbooks, not standalone playbooks
9+
- roles/cloud-ec2/files/ # AWS CloudFormation templates use YAML tags ansible-lint can't parse
10+
- roles/cloud-lightsail/files/ # AWS CloudFormation templates use YAML tags ansible-lint can't parse
911

1012
skip_list:
1113
- 'package-latest' # Package installs should not use latest - needed for updates
@@ -46,4 +48,15 @@ enable_list:
4648

4749
verbosity: 1
4850

51+
# Mock custom modules in library/ that ansible-lint can't auto-discover
52+
# These modules exist and work at runtime, but need to be declared for static analysis
53+
mock_modules:
54+
- gcp_compute_location_info
55+
- lightsail_region_facts
56+
- linode_stackscript_v4
57+
- x25519_pubkey
58+
- linode_v4
59+
- scaleway_compute
60+
- digital_ocean_floating_ip
61+
4962
# vim: ft=yaml

.github/workflows/claude-code-review.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
---
12
name: Claude Code Review
23

3-
on:
4+
'on':
45
pull_request:
56
types: [opened, synchronize]
67
# Optional: Only run on specific file changes
@@ -41,7 +42,13 @@ jobs:
4142
REPO: ${{ github.repository }}
4243
PR NUMBER: ${{ github.event.pull_request.number }}
4344
44-
Please review this pull request and provide feedback on:
45+
IMPORTANT: Before posting your review, minimize any previous review comments from yourself to avoid cluttering the PR:
46+
1. List existing comments: gh api repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments
47+
2. Find comments from "github-actions[bot]" that contain "Code Review" or review-related content in the body
48+
3. For each such comment, minimize it as OUTDATED using:
49+
gh api graphql -f query='mutation($id: ID!) { minimizeComment(input: {subjectId: $id, classifier: OUTDATED}) { minimizedComment { isMinimized } } }' -f id="<node_id>"
50+
51+
Then review this pull request and provide feedback on:
4552
- Code quality and best practices
4653
- Potential bugs or issues
4754
- Performance considerations
@@ -54,4 +61,6 @@ jobs:
5461
5562
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
5663
# or https://docs.claude.com/en/docs/claude-code/cli-reference for available options
57-
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(ansible-playbook * --syntax-check),Bash(ansible-lint *),Bash(ruff check *),Bash(yamllint *),Bash(shellcheck *),Bash(python -m pytest *)"'
64+
# Note: gh api is needed for minimizing old comments (workaround for broken use_sticky_comment)
65+
# See: https://github.com/anthropics/claude-code-action/issues/419
66+
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*),Bash(gh api:*),Bash(ansible-playbook * --syntax-check),Bash(ansible-lint *),Bash(ruff check *),Bash(yamllint *),Bash(shellcheck *),Bash(python -m pytest *)"'

.github/workflows/claude.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
---
12
name: Claude Code
23

3-
on:
4+
'on':
45
issue_comment:
56
types: [created]
67
pull_request_review_comment:

roles/cloud-gce/tasks/prompts.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
- name: Set facts about the default region
4646
set_fact:
4747
default_region: >-
48-
{% for region in gce_regions %}
49-
{%- if region == "us-east1" %}{{ loop.index }}{% endif %}
48+
{% for region in gce_regions -%}
49+
{% if region == "us-east1" %}{{ loop.index }}{% endif %}
5050
{%- endfor %}
5151
5252
- pause:
@@ -65,9 +65,9 @@
6565
- name: Set region as a fact
6666
set_fact:
6767
algo_region: >-
68-
{% if region is defined %}{{ region }}
69-
{%- elif _gce_region.user_input %}{{ gce_regions[_gce_region.user_input | int - 1] }}
70-
{%- else %}{{ gce_regions[default_region | int - 1] }}{% endif %}
68+
{% if region is defined %}{{ region -}}
69+
{% elif _gce_region.user_input %}{{ gce_regions[_gce_region.user_input | int - 1] -}}
70+
{% else %}{{ gce_regions[default_region | int - 1] }}{% endif %}
7171
7272
- name: Get zones
7373
gcp_compute_location_info:
@@ -82,4 +82,4 @@
8282

8383
- name: Set random available zone as a fact
8484
set_fact:
85-
algo_zone: "{{ (gcp_compute_zone_info.resources | random(seed=algo_server_name + algo_region + project_id) ).name }}"
85+
algo_zone: "{{ (gcp_compute_zone_info.resources | random(seed=algo_server_name + algo_region + project_id)).name }}"

roles/cloud-lightsail/tasks/prompts.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
- name: Set the default region
4242
set_fact:
4343
default_region: >-
44-
{% for r in lightsail_regions %}
45-
{%- if r['name'] == "us-east-1" %}{{ loop.index }}{% endif %}
44+
{% for r in lightsail_regions -%}
45+
{% if r['name'] == "us-east-1" %}{{ loop.index }}{% endif %}
4646
{%- endfor %}
4747
4848
- pause:
@@ -61,6 +61,6 @@
6161
- set_fact:
6262
stack_name: "{{ algo_server_name | replace('.', '-') }}"
6363
algo_region: >-
64-
{% if region is defined %}{{ region }}
65-
{%- elif _algo_region.user_input %}{{ lightsail_regions[_algo_region.user_input | int - 1]['name'] }}
66-
{%- else %}{{ lightsail_regions[default_region | int - 1]['name'] }}{% endif %}
64+
{% if region is defined %}{{ region -}}
65+
{% elif _algo_region.user_input %}{{ lightsail_regions[_algo_region.user_input | int - 1]['name'] -}}
66+
{% else %}{{ lightsail_regions[default_region | int - 1]['name'] }}{% endif %}

roles/common/handlers/main.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- name: flush routing cache
66
shell: echo 1 > /proc/sys/net/ipv4/route/flush
7+
changed_when: false
78

89
- name: restart systemd-networkd
910
systemd:
@@ -21,3 +22,4 @@
2122

2223
- name: netplan apply
2324
command: netplan apply
25+
changed_when: false

roles/common/tasks/ubuntu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
args:
3030
executable: /bin/bash
3131
register: reboot_required
32+
changed_when: false
3233

3334
- name: Reboot (kernel updated or performance optimization disabled)
3435
shell: sleep 2 && shutdown -r now "Ansible updates triggered"
@@ -39,6 +40,7 @@
3940
reboot_required.stdout == 'kernel-updated' or
4041
(reboot_required.stdout == 'optional' and not performance_skip_optional_reboots|default(false))
4142
)
43+
changed_when: true
4244
failed_when: false
4345

4446
- name: Skip reboot (performance optimization enabled)

roles/privacy/tasks/auto_cleanup.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@
6161
when: privacy_auto_cleanup.enabled | bool
6262

6363
- name: Clean package cache immediately
64-
shell: |
65-
apt-get clean
66-
apt-get autoclean
64+
apt:
65+
autoclean: true
6766
changed_when: false
6867
when:
6968
- privacy_auto_cleanup.enabled | bool

roles/privacy/tasks/clear_history.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
- /tmp/.font-unix
2626
- /tmp/.ICE-unix
2727
when: privacy_history_clearing.clear_system_history | bool
28-
ignore_errors: true
28+
failed_when: false
2929

3030
- name: Configure bash to not save history for service users
3131
lineinfile:
@@ -44,7 +44,7 @@
4444
export HISTFILESIZE=0
4545
unset HISTFILE
4646
when: privacy_history_clearing.disable_service_history | bool
47-
ignore_errors: true
47+
failed_when: false
4848

4949
- name: Create history clearing script for logout
5050
template:

roles/strongswan/handlers/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
# If StrongSwan is running but we can't reload CRLs, that's a real problem
3535
echo "Failed to reload CRLs after 3 attempts"
3636
exit 1
37+
changed_when: false

0 commit comments

Comments
 (0)