I'd like to write playbooks to install my development environment. Most steps went well, but I'm struggling to install Ruby through asdf
.
Playbooks are splitted and called from a main.yaml
. The one installing asdf
works fine:
---
- hosts: localhost
connection: local
gather_facts: yes
tasks:
- name: Detects previous installations of asdf
command: asdf version > /dev/null
register: asdf_check
ignore_errors: true
- name: Download and install asdf
block:
- name: Clone asdf repository into ~/.asdf
ansible.builtin.git:
name: https://github.com/asdf-vm/asdf.git
dest: ~/.asdf
single_branch: yes
version: v0.14.0
- name: Insert lines to ~/.bashrc to source asdf
ansible.builtin.blockinfile:
path: "/home/{{ unix_username }}/.bashrc"
block: |
. "$HOME/.asdf/asdf.sh"
. "$HOME/.asdf/completions/asdf.bash"
# Note for superuser post:
# I'm not sure to keep this, I added it to try a specific approach described below
- name: Set execution permissions to asdf.sh (reset later on)
ansible.builtin.file:
path: "/home/{{ unix_username }}/.asdf/asdf.sh"
mode: "744"
owner: "{{ unix_username }}"
group: "{{ unix_username }}"
when: asdf_check.rc > 0
But none of the approach I tried successfully installed Ruby latest version. I tried:
- sourcing
~/.bashrc
before callingasdf
- using
asdf
absolute path - using
bash -lc
- using
ansible.builtin.command
- using
ansible.builtin.shell
Using ansible.builtin.command
, bash -lc
and asdf
absolute path: task marked as "changed", but does not install anything
tasks:
- name: Install asdf ruby plugin
ansible.builtin.command: "bash -lc '/home/{{ unix_username }}/.asdf/asdf.sh plugin add ruby https://github.com/asdf-vm/asdf-ruby.git'"
# Other tasks install Ruby latest and register it globally using the same approach
Using ansible.builtin.command
, bash -lc
and source .bashrc
: rc127, asdf: command not found
tasks:
- name: Install asdf ruby plugin
ansible.builtin.command: "bash -lc 'source /home/{{ unix_username }}/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git'"
# Other tasks install Ruby latest and register it globally using the same approach
Using ansible.builtin.shell
and asdf
absolute path: rc127, asdf: command not found
tasks:
- name: Install asdf ruby plugin
ansible.builtin.shell:
executable: /bin/bash
cmd: "/home/{{ unix_username }}/.asdf/asdf.sh plugin add ruby https://github.com/asdf-vm/asdf-ruby.git"
# Other tasks install Ruby latest and register it globally using the same approach
Using ansible.builtin.shell
and source .bashrc
: rc127, asdf: command not found
tasks:
- name: Install asdf ruby plugin
ansible.builtin.shell:
executable: /bin/bash
cmd: "source /home/{{ unix_username }}/.bashrc && asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git"
# Other tasks install Ruby latest and register it globally using the same approach
Beyond finding a working solution for this task, could you explain why all those approaches failed ?