Skip to content

Commit

Permalink
fix: Source asdf init script
Browse files Browse the repository at this point in the history
  • Loading branch information
trallnag committed Oct 21, 2021
1 parent bd3a56e commit ce50080
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 50 deletions.
3 changes: 2 additions & 1 deletion defaults/main.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
asdf_plugin_git_url: ""
asdf_plugin_source: ~/.asdf/asdf.sh
asdf_plugin_shell_executable: /bin/bash
11 changes: 9 additions & 2 deletions meta/argument_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ argument_specs:
Name of the asdf plugin to install. For example `terraform`.
asdf_plugin_git_url:
default: ""
type: str
required: false
description: >-
Expand Down Expand Up @@ -42,8 +41,16 @@ argument_specs:
asdf_plugin_shell_executable:
type: str
required: false
required: true
default: /bin/bash
description: >-
Absolute path to a shell executable that the Ansible Shell module
tasks should use for working with asdf. If this option is unset, this
the module defaults will be used.
asdf_plugin_source:
type: str
required: true
default: ~/.asdf/asdf.sh
description: >-
Asdf source script.
55 changes: 8 additions & 47 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,75 +1,36 @@
# ------------------------------------------------------------------------------
# Add plugin


- name: "{{ asdf_plugin_name }} : Add plugin"
when: asdf_plugin_shell_executable is undefined
ansible.builtin.command: >-
asdf plugin add {{ asdf_plugin_name }} {{ asdf_plugin_git_url }}
changed_when: false

- name: "{{ asdf_plugin_name }} : Add plugin"
when: asdf_plugin_shell_executable is defined
ansible.builtin.shell: >-
source {{ asdf_plugin_source }}
asdf plugin add {{ asdf_plugin_name }} {{ asdf_plugin_git_url }}
args: {executable: "{{ asdf_plugin_shell_executable }}"}
register: task
failed_when: task.rc >= 1 and 'already added' not in task.stderr
changed_when: false


# ------------------------------------------------------------------------------
# Checkout plugin repo at ref


- name: "{{ asdf_plugin_name }} : Checkout plugin repo at ref"
when: asdf_plugin_shell_executable is undefined and asdf_plugin_git_ref is defined
ansible.builtin.command: >-
asdf plugin update {{ asdf_plugin_name }} {{ asdf_plugin_git_ref }}
changed_when: false

- name: "{{ asdf_plugin_name }} : Checkout plugin repo at ref"
when: asdf_plugin_shell_executable is defined and asdf_plugin_git_ref is defined
ansible.builtin.shell: >-
source {{ asdf_plugin_source }}
asdf plugin update {{ asdf_plugin_name }} {{ asdf_plugin_git_ref }}
args: {executable: "{{ asdf_plugin_shell_executable }}"}
changed_when: false


# ------------------------------------------------------------------------------
# Install package


- name: "{{ asdf_plugin_name }} : Install package {{ asdf_plugin_package_versions | default('SKIP') }}"
when: asdf_plugin_shell_executable is undefined and asdf_plugin_package_versions is defined
ansible.builtin.command: >-
asdf install {{ asdf_plugin_name }} {{ item }}
loop: "{{ asdf_plugin_package_versions }}"
register: task
failed_when: task.rc > 0 or 'fatal' in task.stdout or 'error' in task.stdout
changed_when: false

- name: "{{ asdf_plugin_name }} : Install package {{ asdf_plugin_package_versions | default('SKIP') }}"
when: asdf_plugin_shell_executable is defined and asdf_plugin_package_versions is defined
ansible.builtin.shell: >-
source {{ asdf_plugin_source }}
asdf install {{ asdf_plugin_name }} {{ item }}
loop: "{{ asdf_plugin_package_versions }}"
args: {executable: "{{ asdf_plugin_shell_executable }}"}
changed_when: false


# ------------------------------------------------------------------------------
# Set the global version


- name: "{{ asdf_plugin_name }} : Set global version to {{ asdf_plugin_package_version_global | default('SKIP') }}"
when: asdf_plugin_shell_executable is undefined and asdf_plugin_package_version_global is defined
ansible.builtin.command: >-
asdf global {{ asdf_plugin_name }} {{ asdf_plugin_package_version_global }}
changed_when: false

- name: "{{ asdf_plugin_name }} : Set global version to {{ asdf_plugin_package_version_global | default('SKIP') }}"
when: asdf_plugin_shell_executable is defined and asdf_plugin_package_version_global is defined
ansible.builtin.shell: >-
source {{ asdf_plugin_source }}
asdf global {{ asdf_plugin_name }} {{ asdf_plugin_package_version_global }}
args: {executable: "{{ asdf_plugin_shell_executable }}"}
changed_when: false


# ------------------------------------------------------------------------------

0 comments on commit ce50080

Please sign in to comment.