Skip to content

fix(ansible): skip missing user hooks source - #147

Merged
dngrtech merged 3 commits into
mainfrom
fix/skip-missing-user-hooks-sync
Jul 11, 2026
Merged

fix(ansible): skip missing user hooks source#147
dngrtech merged 3 commits into
mainfrom
fix/skip-missing-user-hooks-sync

Conversation

@dngrtech

Copy link
Copy Markdown
Owner

Summary

  • check whether the local instance user-hooks/ directory exists before synchronizing
  • skip only the optional hook sync when the directory is absent
  • preserve remote user-hooks/ creation and normal sync/delete behavior when a source exists

Root cause

Legacy instances may not have a local user-hooks/ directory. The unconditional synchronize task then exits with rsync code 23, causing Ansible RC 2 and incorrectly leaving an otherwise-running instance in ERROR.

Test plan

  • pytest -q tests/test_sync_configs_playbook_hooks.py tests/test_service_enablement_playbooks.py (4 passed)
  • ansible-playbook --syntax-check ansible/playbooks/sync_instance_configs_and_restart.yml -i "localhost,"
  • Full suite: 987 passed, 37 unrelated environment/baseline failures (SECRET_KEY missing, Redis auth, existing script-validation failure)

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: fix(ansible): skip missing user hooks source

Strengths

  • Correct Ansible pattern: Using ansible.builtin.stat + register + when: <reg>.stat.exists is the idiomatic way to guard against missing source paths in Ansible — well applied here.
  • Least-privilege maintained: Both the stat task and the sync task carry become: false and delegate_to: localhost, consistent with the existing task posture.
  • Test coverage matches the change: The test updates verify all three meaningful properties of the new stat task (path, delegate_to, become) and confirm the when guard was wired onto the sync task.
  • Minor DRY improvement in tests: Caching _tasks() in a local variable (tasks) avoids parsing the YAML twice in test_playbook_syncs_user_hooks_with_delete — small but correct.

Issues

Critical (Must Fix)

None.

Important (Should Fix)

test_playbook_syncs_user_hooks_with_delete now tests two unrelated things

  • tests/test_sync_configs_playbook_hooks.py:27–38
  • The function was originally scoped to the sync-with-delete behaviour. It now also asserts properties of the stat task. If either concern breaks, the failure message points at the wrong test name, making diagnosis slower.
  • Fix: Extract the stat assertions into a dedicated test_playbook_checks_user_hooks_source_before_sync function.

Minor (Nice to Have)

when condition stored as a plain string in YAML

  • ansible/playbooks/sync_instance_configs_and_restart.yml:90
  • when: user_hooks_source.stat.exists is correct and works, but Ansible also accepts the boolean expression form when: user_hooks_source.stat.exists | bool which makes intent more explicit in newer lint rules. Not a bug; lint-level only.

Assessment

Ready to merge? Yes

Reasoning: This is a focused, low-risk guard against a missing source directory that previously caused an unconditional rsync failure. The logic is correct, the tests cover the new behaviour, and there are no security or compatibility regressions.

rage added 2 commits July 11, 2026 00:44
Review on PR #147 noted test_playbook_syncs_user_hooks_with_delete
asserted two unrelated tasks, so a failure would point at the wrong
test name.
@dngrtech
dngrtech force-pushed the fix/skip-missing-user-hooks-sync branch from 74a5dd4 to 9998f2b Compare July 11, 2026 07:44
@dngrtech
dngrtech merged commit 72678b1 into main Jul 11, 2026
@dngrtech
dngrtech deleted the fix/skip-missing-user-hooks-sync branch July 11, 2026 07:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant