Skip to content

Commit

Permalink
Added idempotency on global versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
waewoo007 committed Nov 20, 2022
1 parent 51a42a8 commit a5e45f2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions filter_plugins/asdf_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
def get_asdf_global_version(asdf_plugin_item):
return asdf_plugin_item['global'] or asdf_plugin_item['versions']
#| difference(asdf_plugin_item.delete_versions|default([])) | sort | first)

class FilterModule(object):

def filters(self):
return {
'get_asdf_global_version': get_asdf_global_version
}
19 changes: 17 additions & 2 deletions tasks/plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,25 @@
become: True
become_user: "{{ asdf_user }}"

- name: "set global app versions"
command: "bash -lc 'source /etc/profile.d/asdf.sh && asdf global {{ item.name }} {{ item.global | default(item.versions | difference(item.delete_versions|default([])) | sort | first) }}'"
- name: "check global app versions"
shell: |
source /etc/profile.d/asdf.sh
cat {{ ansible_env.ASDF_DEFAULT_TOOL_VERSIONS_FILENAME }} | grep "^{{ item.name }}\s*{{ item | get_asdf_global_version }}$" | tr -s "[:blank:]" _
args:
executable: /bin/bash
when: item.versions is defined
with_items: "{{ asdf_plugins }}"
register: asdf_global
changed_when: false
become: True
become_user: "{{ asdf_user }}"

- name: "set missing global app versions"
command: "bash -lc 'source /etc/profile.d/asdf.sh && asdf global {{ item.name }} {{ item | get_asdf_global_version }}'"
when: >
item.versions is defined
and '_'.join((item.name, item | get_asdf_global_version | string)) not in (asdf_global.results|map(attribute="stdout_lines") | list | flatten)
with_items: "{{ asdf_plugins }}"
become: True
become_user: "{{ asdf_user }}"

Expand Down

0 comments on commit a5e45f2

Please sign in to comment.