This question already has an answer here:
I want to list the files as per the host name.But problem is i not able to use the wildcard with variable properly.Can someone suggest me on this.
---
- hosts: local
become_user: yes
vars:
filename: /root/stuff
tasks:
- name: list files
action: command ls -lrt {{ filename }}/'*{{ansible_hostname}}'
register: listfiles
- debug: var=listfiles
If your question is why * doesn't expand?, then:
command
module:shell
module:So if you need any shell tricks, like wildcard expansion or access to environment variables, use
shell
module.