In a Vagrant setup, I use Ansible to provision the virtual machine.
In one of the Ansible roles, I have a task that copies some files inside ~/bin/
folder:
~/bin/one.sh
~/bin/two.sh
I want to create symlinks of those files so the end result looks like:
~/bin/one.sh
~/bin/two.sh
~/bin/one
(symlink to ~/bin/one.sh
)
~/bin/two
(symlink to ~/bin/two.sh
)
How can I achieve that? So far I have tried this but it doesn't work:
- name: Common tasks =>Create symlinks for utilities
file: src=~/bin/{{ item }} dest=~/bin/ mode=755 state=link
with_fileglob:
- bin/*
I need to put a regex inside dest=~/bin/
that takes the file name (like one.sh
) and removes the extension (one.sh
becomes one
) but I'm not sure how to do it.
Update
I finally used this tasks:
- name: Copy common files to ~/bin
copy: src={{ item }} dest=~/bin/ mode=755
with_fileglob:
- bin/*
- name: Ensure symlinks for utilities exist
file: src=~/bin/{{ item | basename | regex_replace('(\w+(?:\.\w+)*$)', '\1') }} dest=~/bin/{{ item | basename | regex_replace('\.sh','') }} mode=755 state=link
with_fileglob:
- bin/*