On Friday, 21 December 2018 11:55:19 CET [email protected] wrote:
> Hi Team,
> 
> I am trying to remove and create the directory in single task but it is 
> failing. Could someone please help.
> 
> vars/main.yml
> 
> SAMPLE:
> - { src: '/tmp/abc.war', dest: '/tmp/test/' }
> - { src: '/tmp/def.war', dest: 'tmp/test/' }
> - { src: '/tmp/xyz.war', dest: '/tmp/test/' }
> 
> Playbook.yml
> ---
> - hosts: all
>     tasks:
>     - name: Ansible remove and create directory
>       file:
>         path: "{{ item.dest }}"
>         state: absent
>     with_items:
>         - { "SAMPLE", state: absent }
>         - { "SAMPLE", state: directory }

You need to use with_nested:
https://docs.ansible.com/ansible/2.4/playbooks_loops.html#nested-loops


-- 
Kai Stian Olstad


-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2221156.siFsWOr9Ju%40x1.
For more options, visit https://groups.google.com/d/optout.

Reply via email to