1

Hellos. I need to delete a few directories on a group of machines. I can't seem to get the file module to do my bidding. The below module will run without error and does not delete anything. I do not want to remove /opt.

- hosts: [dummies]   tasks:
    - name: destroy these paths!
      file: path=/opt{{ item }} state=absent recurse=no
      with_items:
        - "foo"
        - "bar"
        - "baz"
6

I don't think Ansible is going to add a slash for you.

file: path=/opt/{{ item }}
0
0

For new version of Ansible it does consider / for i am running below for creating the directories:

  - name: Creating /dir1 & /dir2
    file:
      path: "{{ item }}"
      state: directory
    with_items:
     - /dir1
     - /dir2

If we have remove directories i think below should work:

  - name: Removing dir1 & dir2
    file:
      path: "{{ item }}"
      state: absent
    with_items:
     - dir1
     - dir2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.