Skip to content

Commit

Permalink
replace with_* with loop
Browse files Browse the repository at this point in the history
  • Loading branch information
bhcleek committed Jan 2, 2025
1 parent af9f379 commit 89c25f1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 17 deletions.
9 changes: 3 additions & 6 deletions roles/developer/tasks/git-workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@
## (see: https://stackoverflow.com/questions/15935624/how-do-i-avoid-empty-sections-when-removing-a-setting-from-git-config)
#- name: keep url section
# command: git config -f "{{ ansible_env.HOME }}/.config/git/{{ workspace.name }}.inc" "url.{{ item.base }}.placeholder" placeholder
# with_items: "{{ workspace.insteadOfs }}"
# loop: "{{ workspace.insteadOfs }}"

- name: remove workspace insteadOf values
command: git config unset -f "{{ ansible_env.HOME }}/.config/git/{{ workspace.name }}.inc" --all "url.{{ item.base | default("") }}.insteadOf"
with_items: "{{ workspace.insteadOfs | default([]) }}"
loop: "{{ workspace.insteadOfs | default([]) }}"
when: item.base is defined

- name: git config workspace insteadOf
command: git config -f "{{ ansible_env.HOME }}/.config/git/{{ workspace.name }}.inc" --add url.{{ item.0.base }}.insteadOf "{{ item.1 }}"
with_subelements:
- "{{ workspace.insteadOfs | default([]) }}"
- urls
- skip_missing: yes
loop: "{{ workspaces.insteadOfs | default([]) | subelements('urls', skip_missing=True) }}"

- name: git config includeIf workspace
command: git config --global --replace-all includeIf."gitdir:{{ workspace.gitdir }}".path {{ workspace.name }}.inc
11 changes: 4 additions & 7 deletions roles/developer/tasks/git.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,16 @@
# (see: https://stackoverflow.com/questions/15935624/how-do-i-avoid-empty-sections-when-removing-a-setting-from-git-config)
#- name: keep url section
# command: git config --global "url.{{ item.base }}.placeholder" placeholder
# with_items: "{{ insteadOfs }}"
# loop: "{{ insteadOfs }}"
#
- name: remove insteadOf values
command: git config unset --global --all "url.{{ item.base }}.insteadOf"
with_items: "{{ insteadOfs }}"
loop: "{{ insteadOfs }}"
when: item.base is defined

- name: git config insteadOf
command: git config --global --add url.{{ item.0.base }}.insteadOf "{{ item.1 }}"
with_subelements:
- "{{ insteadOfs }}"
- urls
- skip_missing: yes
loop: "{{ insteadOfs | subelements('urls', skip_missing=True) }}"

- name: git config web.browser
command: git config --global web.browser open
Expand All @@ -125,7 +122,7 @@

# TODO(bc): replace include with include_tasks in Ansible 2.4
- include_tasks: git-workspace.yml
with_items: "{{ workspaces }}"
loop: "{{ workspaces }}"
when: workspaces | default([], true)
loop_control:
loop_var: workspace
2 changes: 1 addition & 1 deletion roles/developer/tasks/install-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
GOOS: "{{ item | lower }}"
GOARCH: amd64
PATH: /usr/local/go/bin:{{ ansible_env.PATH }}
with_items:
loop:
- Linux
- Darwin
when: ansible_system != item
Expand Down
2 changes: 1 addition & 1 deletion roles/developer/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# state: latest
# virtualenv: "{{ venv }}"
# virtualenv_command: "python3 -m venv"
# with_items:
# loop:
# tags:
# - packages
# - python
Expand Down
2 changes: 1 addition & 1 deletion roles/developer/tasks/packages_Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

#- name: install packages
# homebrew_cask: name="{{ item }}" state=present
# with_items:
# loop:
# - slack
# tags:
# - packages
2 changes: 1 addition & 1 deletion roles/developer/tasks/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
command: go install google.golang.org/protobuf/{{ item }}@latest
#environment:
# GOPATH: "{{ansible_env.GOPATH}}"
with_items:
loop:
- cmd/protoc-gen-go

0 comments on commit 89c25f1

Please sign in to comment.