Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ansible : Splitting a string based on delimiter

I have the following string in an ansible variable, xyz

xyz = "/u01/dbbackup_nfs/orabackups/odaserver-c/database/857970682/akash_2/db"

I want to split this string such that I stop at orabackups and do a set_fact of the variable abc , such that abc will have the following value.

set_fact:
  abc: "/u01/dbbackup_nfs"

Any suggestions on this would be really helpful

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The declaration below

  abc: "/{{ xyz.split('/')[1:3]|join('/') }}"

gives what you want

  abc: /u01/dbbackup_nfs
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading