Skip to content

Commit

Permalink
feat: Add option to set shell executable
Browse files Browse the repository at this point in the history
Covered in the following GitHub issue:

    #5
  • Loading branch information
trallnag committed Oct 16, 2021
1 parent fa47226 commit 2381b60
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
8 changes: 8 additions & 0 deletions meta/argument_specs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ argument_specs:
required: false
description: >-
Set the package global version.
asdf_plugin_shell_executable:
type: str
required: false
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.
68 changes: 64 additions & 4 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,91 @@
# ------------------------------------------------------------------------------
# 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 }}
register: task
failed_when: task.rc >= 1 and 'already added' not in task.stderr
changed_when: task.rc == 0

- name: "{{ asdf_plugin_name }} : Add plugin"
when: asdf_plugin_shell_executable is defined
ansible.builtin.shell: >-
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: task.rc == 0


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


- name: "{{ asdf_plugin_name }} : Checkout plugin repo at ref"
when: asdf_plugin_git_ref is defined
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 }}
register: task
failed_when: task.rc > 0 or 'fatal' in task.stdout or 'error' in task.stdout
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: >-
asdf plugin update {{ asdf_plugin_name }} {{ asdf_plugin_git_ref }}
args: {executable: "{{ asdf_plugin_shell_executable }}"}
register: task
failed_when: task.rc > 0 or 'fatal' in task.stdout or 'error' in task.stdout
changed_when: false


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


- name: "{{ asdf_plugin_name }} : Install package {{ asdf_plugin_package_versions | default('SKIP') }}"
when: asdf_plugin_package_versions is defined
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
changed_when: false

- name: "{{ asdf_plugin_name }} : Set the global version to {{ asdf_plugin_package_version_global | default('SKIP') }}"
when: asdf_plugin_package_version_global is defined
- 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: >-
asdf install {{ asdf_plugin_name }} {{ item }}
loop: "{{ asdf_plugin_package_versions }}"
args: {executable: "{{ asdf_plugin_shell_executable }}"}
register: task
failed_when: task.rc > 0
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 }}
register: task
failed_when: task.rc > 0
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: >-
asdf global {{ asdf_plugin_name }} {{ asdf_plugin_package_version_global }}
args: {executable: "{{ asdf_plugin_shell_executable }}"}
register: task
failed_when: task.rc > 0
changed_when: false


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

0 comments on commit 2381b60

Please sign in to comment.