On 07. nov. 2017 19:21, Marc Haber wrote:
> Hi,
> 
> I am trying to remove a bunch of files wiht the following code:
> 
> $ cat site.yml
> ---
> - name: apply common configuration
>    hosts: all
>    remote_user: root
>    become: "yes"
>    roles:
>      - common
> $ cat roles/common/tasks/repos.yml
> ---
> - name: remove extra files that may be on the systems
>    file:
>      path: "{{ item }}"
>      state: absent
>    with_fileglob:
>      - "/etc/apt/sources.list.d/zda-*.list"
>      - "/etc/apt/sources.list.d/exp-mc.list"
>      - "/etc/apt/sources.list.d/sid-mc.list"
>      - "/etc/apt/sources.list.d/sid-zg-stable-mc.list"
>      - "/etc/apt/sources.list.d/sid-zg-unstable-mc.list"
>      - "/etc/apt/sources.list.d/stretch-mc.list"
>      - "/etc/apt/sources.list.d/stretch-security.list"
>      - "/etc/apt/sources.list.d/stretch-zg-stable-mc.list"
>      - "/etc/apt/sources.list.d/stretch-zg-unstable-mc.list"
>      - "/etc/apt/sources.list.d/buster-mc.list"
>      - "/etc/apt/sources.list.d/stretch-zg-stable-mc.list"
>      - "/etc/apt/sources.list.d/stretch-security.list"
>      - "/etc/apt/preferences.d/??-zda-*.pref"
>      - "/etc/apt/preferences.d/10-sid-zg-unstable-mc.pref"
>      - "/etc/apt/preferences.d/20-sid-zg-stable-mc.pref"
>      - "/etc/apt/preferences.d/50-sid-security.pref"
>      - "/etc/apt/preferences.d/70-sid.pref"
>      - "/etc/apt/preferences.d/99-default.pref"
> - name: include repositories
>    tags:
>            repos
>    include_tasks:
>            "{{distribution}}/{{distribution_version}}/repos.yml"
> $
> 
> My target system contains the following files:
> -rw-r--r-- 1 root root    0 Nov  7 19:06 zda-foo.list
> -rw-r--r-- 1 root root   63 Nov  7 19:03 zda-sid-mc.list
> -rw-r--r-- 1 root root   75 Nov  7 19:03 zda-sid-zg-stable-mc.list
> -rw-r--r-- 1 root root   77 Nov  7 19:03 zda-sid-zg-unstable-mc.list
> 
> Running the playbook tries to remove two files that are not there but
> leaves the files in place:


with_fileglob is a lookup plugin, and lookup plugin runs on the Ansible 
controller and not the remote host.

To do what what you want to do, you must use the find module to find the files 
and register the output in a variable.
Then you can delete them with the file module and with_items.


-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/efe443fe-eb65-f92e-4b59-2f9d73a6c2f6%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to