ansible-role-asdf icon indicating copy to clipboard operation
ansible-role-asdf copied to clipboard

failed: set global app version

Open kmptkp opened this issue 3 years ago • 2 comments

While installing erlang and elixir, the role never gets past the step TASK [asdf : set global app versions]

The error is:

failed: [lxd] (item={'name': 'erlang', 'versions': ['25.1']}) => {"ansible_loop_var": "item", "changed": true, "cmd": ["bash", "-lc", "source /etc/profile.d/asdf.sh && asdf global erlang 25.1"], "delta": "0:00:00.182398", "end": "2022-12-07 19:43:49.179097", "item": {"name": "erlang", "versions": ["25.1"]}, "msg": "non-zero return code", "rc": 1, "start": "2022-12-07 19:43:48.996699", "stderr": "/home/foo/.asdf/lib/functions/versions.bash: line 67: /home/foo//home/foo/.tool-versions: No such file or directory", "stderr_lines": ["/home/foo/.asdf/lib/functions/versions.bash: line 67: /home/foo//home/foo/.tool-versions: No such file or directory"], "stdout": "", "stdout_lines": []}

failed: [lxd] (item={'name': 'elixir', 'versions': ['1.14']}) => {"ansible_loop_var": "item", "changed": true, "cmd": ["bash", "-lc", "source /etc/profile.d/asdf.sh && asdf global elixir 1.14"], "delta": "0:00:00.151380", "end": "2022-12-07 19:43:49.384590", "item": {"name": "elixir", "versions": ["1.14"]}, "msg": "non-zero return code", "rc": 1, "start": "2022-12-07 19:43:49.233210", "stderr": "/home/foo/.asdf/lib/functions/versions.bash: line 67: /home/foo//home/foo/.tool-versions: No such file or directory", "stderr_lines": ["/home/foo/.asdf/lib/functions/versions.bash: line 67: /home/foo//home/foo/.tool-versions: No such file or directory"], "stdout": "", "stdout_lines": []}

Notice the doubling of the path in /home/foo//home/foo/.tool-versions. This may (or may not!) be related to the fact that export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="/home/foo/.tool-versions" gets written to /etc/profile.d/asdf.sh (whereas the var name suggests that it should be ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=".tool-versions", thereby triggering the path-doubling). Changing that manually doesn't help as it gets overwritten on every ansible run.

The relevant part of my vars section:

asdf_user: foo
asdf_group: foo
asdf_version: "v0.10.2"
asdf_plugins:
  - name: erlang
    versions: ["25.1"]
    global: "25.1"
  - name: elixir
    versions: ["1.14"]
    global: "1.14"

Note that it uses asdf v0.10.2 versus v0.8.1 in defaults/main.yml.

Finally the role is just called with the role name (and works fine until the task setting globals), nothing special to show.

kmptkp avatar Dec 07 '22 18:12 kmptkp

Indeed this issue is fixed by changing the task from:

- name: "set asdf_default_tool_versions_file based on home directory"
  set_fact:
    asdf_default_tool_versions_file: "{{ getent_passwd[asdf_user][4] }}/.tool-versions"
  when: asdf_dir is undefined and asdf_default_tool_versions_file is undefined

to

- name: "set asdf_default_tool_versions_file based on home directory"
  set_fact:
    asdf_default_tool_versions_file: ".tool-versions"
  when: asdf_dir is undefined and asdf_default_tool_versions_file is undefined

I'm not sure sure how this changes affects the v0.8-based versions, and it is a trivial 1-line change, so I haven't made a PR for now.

kmptkp avatar Dec 07 '22 19:12 kmptkp

FYI, from asdf v0.10.2, this file was added :

https://github.com/asdf-vm/asdf/blob/v0.10.2/lib/functions/versions.bash

and line 23, for global command, they force the use of $HOME.

fapeliberty avatar Feb 07 '23 13:02 fapeliberty