Writing

Ruby's String#split method in Ansible Playbook

Ansible Playbook

Table of Contents
  1. 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:

---
- 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"

Related Posts