This is the same question as you asked in an earlier thread - to which you got two answers. Without any feedback on how that worked out for you (did you actually try them? did they work?), you are now trying almost the same solution again, which is failing in a similar way. Instead of shoehorning what you think should work and ignoring the provided answers, can you please read them and try them out?
In any case, removing and recreating directories in a single task sounds like a bad thing to do to begin with. To give some hint, in order of elegance, the options are: 1. find and register all files/dirs, and then delete those 2. use a shell task to "rm -rf" the contents Dick On Fri, 21 Dec 2018 at 11:55, <[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 } > > > ERROR: > > {"msg": "The task includes an option with an undefined variable. The error > was: 'dict object' has no attribute 'path'\n\nThe error appears to have been > in '/etc/ansible/test/tasks/main.yml': line 23, column 5, but may\nbe > elsewhere in the file depending on the exact syntax problem.\n\nThe offending > line appears to be:\n\n\n - name: ansible create directory example\n ^ > here\n"} > > > -- > 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/60202e37-9d08-4655-bd28-1aef955d4cd8%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 [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/CAL8fbwMEDO1NZaYJ3Rt-BZ1yz-yjOtchcFntiV%3DuR%2BCm%2BKNCmQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
