Skip to content
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

Add idempotency on global versioning #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions filter_plugins/asdf_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# -*- coding: utf-8 -*-
def get_asdf_global_version(asdf_plugin_item):
list_version = list(set(asdf_plugin_item['versions']).difference(set(asdf_plugin_item.get('delete_versions', []))))
list_version.sort()
return asdf_plugin_item.get('global', list_version[0])

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 $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME | grep "^${TOOL_NAME}\s*" | grep "\s*${TOOL_VERSION}\(\s*\|$\)" | 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