Created
March 31, 2014 14:24
-
-
Save angstwad/9893480 to your computer and use it in GitHub Desktop.
Splitting in Jinja2/Ansible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Test split | |
hosts: localhost | |
gather_facts: false | |
vars: | |
- facter_blockdevices: "sda,sdb,sdc,sdd,sde,sdf" | |
tasks: | |
- name: Let's split | |
debug: var=item | |
with_items: "facter_blockdevices.split(',')" |
Author
angstwad
commented
Mar 31, 2014
Hi,
How to split the string inside the loop?
Inside the with_items loop the {{ item }} gets a value like "/roles/files/external/example.values.db" and I just need the "example.values.db" for validation ...
Thanks,
Constantin
@Constantin07, use {{ item | basename }}
.
This didnt work me, but
---
- name: Test split
hosts: localhost
gather_facts: false
vars:
- facter_blockdevices: "sda,sdb,sdc,sdd,sde,sdf"
tasks:
- name: Let's split
debug: var=item
with_items: "{{ facter_blockdevices.split(',') }}"
does:
ansible-playbook mytest.yml
PLAY [Test split] *****************************************************************************************************************************
TASK [Let's split] ****************************************************************************************************************************
ok: [localhost] => (item=sda) => {
"item": "sda"
}
ok: [localhost] => (item=sdb) => {
"item": "sdb"
}
ok: [localhost] => (item=sdc) => {
"item": "sdc"
}
ok: [localhost] => (item=sdd) => {
"item": "sdd"
}
ok: [localhost] => (item=sde) => {
"item": "sde"
}
ok: [localhost] => (item=sdf) => {
"item": "sdf"
}
PLAY RECAP ************************************************************************************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=0
I get the following output when i try this. Please help.
TASK [Let's split] ************************************************************************************************************************************************************
ok: [localhost] => (item=None) => {}
ok: [localhost] => (item=None) => {}
ok: [localhost] => (item=None) => {}
ok: [localhost] => (item=None) => {}
ok: [localhost] => (item=None) => {}
ok: [localhost] => (item=None) => {}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment