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
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With