-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update ansible git to only clone when repo isn't there #95
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe changes in the Ansible playbook located in Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Ansible
participant GitRepo
User->>Ansible: Start playbook
Ansible->>GitRepo: Check if repo exists
alt Repo does not exist
Ansible->>GitRepo: Clone repository
else Repo exists
Ansible->>GitRepo: Pull latest changes
end
Ansible->>User: Complete playbook
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
sidecar/ansible/provision.yaml (2)
71-77
: Consider adding safety parameters and making the branch configurable.While the pull task is well-structured, consider these improvements:
- Add
force: no
to prevent discarding local changes- Make the branch configurable via a variable instead of hardcoding 'main'
- name: Pull repository if it does exist git: repo: 'https://github.com/private-attribution/draft.git' dest: '{{ ansible_env.HOME }}/draft' clone: false - version: main + version: "{{ git_branch | default('main') }}" + force: no when: git_repo.stat.exists
59-77
: Consider DRY principle and error handling improvements.A few suggestions to enhance maintainability and reliability:
- Define the repository URL as a variable to avoid duplication
- Add error handling for Git operations
Example refactor:
- name: Set Git variables set_fact: git_repo_url: 'https://github.com/private-attribution/draft.git' git_repo_path: '{{ ansible_env.HOME }}/draft' # ... your existing stat check ... - name: Clone repository if it doesn't exist git: repo: '{{ git_repo_url }}' dest: '{{ git_repo_path }}' when: not git_repo.stat.exists register: git_clone_result ignore_errors: yes - name: Handle Git clone failure fail: msg: "Failed to clone repository: {{ git_clone_result.msg }}" when: git_clone_result.failed is defined and git_clone_result.failed - name: Pull repository if it does exist git: repo: '{{ git_repo_url }}' dest: '{{ git_repo_path }}' clone: false version: "{{ git_branch | default('main') }}" force: no when: git_repo.stat.exists register: git_pull_result ignore_errors: yes - name: Handle Git pull failure fail: msg: "Failed to pull repository: {{ git_pull_result.msg }}" when: git_pull_result.failed is defined and git_pull_result.failed
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
sidecar/ansible/provision.yaml
(1 hunks)
🔇 Additional comments (2)
sidecar/ansible/provision.yaml (2)
59-63
: LGTM! Well-structured directory check.
The implementation correctly uses the stat
module to check for the Git repository's existence, and properly registers the result for conditional execution of subsequent tasks.
68-68
: LGTM! Proper conditional execution added.
The condition ensures the clone operation only runs when necessary, improving efficiency and maintaining idempotency.
small ansible change
Summary by CodeRabbit
New Features
Bug Fixes