skadoo sh
skadoo sh

Reputation: 51

Ansible : Split a string with multiple spaces as delimiter

I am trying to split a string multiple spaces as delimiter in Ansible.

 - name: Build Archive files 123.
    set_fact:
      archfilesloc: "{{ archfiles.split(\" +\")[1] }}" doesnt work
 - name: Build Archive files 123.
    set_fact:
      archfilesloc: "{{ archfiles.split(\"\\s+\")[1] }}"doesnt work
 - name: Build Archive files 123.
    set_fact:
      archfilesloc: "{{ archfiles.split(\"[\\s+]\")[1] }}" doesnt work

Upvotes: 4

Views: 2220

Answers (1)

aru_sha4
aru_sha4

Reputation: 378

Try the following:

archfiles.split()[1]

Here, split() is a Python function and behaves exactly like it does in python.

See: https://www.geeksforgeeks.org/python-string-split/

Upvotes: 3

Related Questions