Ruby’s String#split method in Ansible Playbook

Today I learned:

Ruby’s String#split method in Ansible Playbook

In Ansible Playbooks you can use Ruby’s String#split method to extract filenames without file path:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
---
- hosts: DEVSRV
  become: yes
  tasks:
  - name: symlink deploy_config scripts
    file:
      src: "{{ item }}"
      dest: "/usr/local/bin/{{ item.split('/') | last }}"
      state: link
    loop:
    - "/home/foo/bar/deploy/config/dev_deploy_config.sh"
    - "/home/foo/bar/deploy/config/int_deploy_config.sh"
    - "/home/foo/bar/deploy/config/prod_deploy_config.sh"