Tom Cannaerts
2014-06-20 11:50:03 UTC
I'm writing a playbook to create a number of solr cores, but I'm running
into some issues.
I started with a task file that would be included, but appearantly include
and with_items isn't supported.
The idea was, that for every core I would check that the base folder of the
core existed. This result (stat) would be saved to a variable.
- name: check for core existence
stat: path=/usr/share/solr/live/solr/cores/{{ item.name }}
register: st_cores
with_items: solr_cores
Then, to enumerate over it in later tasks, I could use the
with_indexed_items and use a conditional when to exclude the cores that
were already present
eg:
- name: Copy example core
shell: cp -R /usr/share/solr/example/solr/collection1/conf/*
/usr/share/solr/live/solr/cores/{{ item.0.name }}/conf/
with_items: solr_cores
when: not st_cores.results[{{ item.0 }}].stat.exists
This works fine for most of the tasks, but I also have a number of tasks
that use with_items themselves. I managed to combine them using
with_nested, but I can't figure out how to include the conditional, as I
don't have the index as with with_indexed_items
eg.
- name: Copy some files
shell: cp /some/folder/{{ item[1] }} /usr/share/solr/cores/{{
item[0].name }}/
with_nested:
- solr_cores
- [ 'somefile.xml', 'anotherfile.xml', 'evenmorefiles.xml' ]
when: not st_cores.results[{{ item[0].0 }}].stat.exists
Basically, I can't check stat results, as I don't know the index of the
current item in that array. Any ideas on how I can solve this? Either I
need a way to be able to check for the file existance on some other way
that does work with with_nested, or I need some sort of creative workaround
for the include with_items problem.
into some issues.
I started with a task file that would be included, but appearantly include
and with_items isn't supported.
The idea was, that for every core I would check that the base folder of the
core existed. This result (stat) would be saved to a variable.
- name: check for core existence
stat: path=/usr/share/solr/live/solr/cores/{{ item.name }}
register: st_cores
with_items: solr_cores
Then, to enumerate over it in later tasks, I could use the
with_indexed_items and use a conditional when to exclude the cores that
were already present
eg:
- name: Copy example core
shell: cp -R /usr/share/solr/example/solr/collection1/conf/*
/usr/share/solr/live/solr/cores/{{ item.0.name }}/conf/
with_items: solr_cores
when: not st_cores.results[{{ item.0 }}].stat.exists
This works fine for most of the tasks, but I also have a number of tasks
that use with_items themselves. I managed to combine them using
with_nested, but I can't figure out how to include the conditional, as I
don't have the index as with with_indexed_items
eg.
- name: Copy some files
shell: cp /some/folder/{{ item[1] }} /usr/share/solr/cores/{{
item[0].name }}/
with_nested:
- solr_cores
- [ 'somefile.xml', 'anotherfile.xml', 'evenmorefiles.xml' ]
when: not st_cores.results[{{ item[0].0 }}].stat.exists
Basically, I can't check stat results, as I don't know the index of the
current item in that array. Any ideas on how I can solve this? Either I
need a way to be able to check for the file existance on some other way
that does work with with_nested, or I need some sort of creative workaround
for the include with_items problem.
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a2683cae-affc-4636-8f3e-3dd76b02c143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+***@googlegroups.com.
To post to this group, send email to ansible-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a2683cae-affc-4636-8f3e-3dd76b02c143%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.