installing `uv` with ansible
I like uv so much I'm using it on servers to deploy random python
things. The default instructions are a bit annoying for automation,
though, so here's what I do instead:
roles/something/tasks/main.yaml:
- name: Install uv
become: true
become_user: "{{ some_user }}"
become_method: machinectl
become_exe: 'sudo machinectl'
vars:
ansible_ssh_pipelining: no
block:
- name: Install uv
# TODO: make this support upgrades
ansible.builtin.shell: "curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/{{ uv_version }}/uv-installer.sh | sh"
args:
creates: "{{ some_path }}/.local/bin/uv"
roles/something/vars/main.yaml:
uv_version: "0.7.6"
As the TODO suggests, this won't upgrade very well - the creates
guard means it'll only ever touch this once. I guess an easy answer
is to mv the binary to uv-{{ uv_version }} which can force
updates, then separately manage a symlink from uv to uv-{{ uv_version }}, but that seems a bit crap. It is also super easy to
do, though.
Note, that's a load-bearing ansible_ssh_pipelining: no - without it,
you get bizarre errors from Ansible about YAML deserialisation or
something. It also needs systemd-container and acl installed so
machinectl exists, and ansible can use filesystem ACLs to make a
temporary file shared between root and the random user (I think it was
that).