0

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
samir
  • 345
  • 2
  • 6
  • 15

1 Answers1

0

If your question is why * doesn't expand?, then:

command module:

The command module takes the command name followed by a list of space-delimited arguments. The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $HOME and operations like "<", ">", "|", and "&" will not work

shell module:

The shell module takes the command name followed by a list of space-delimited arguments. It is almost exactly like the command module but runs the command through a shell (/bin/sh) on the remote node.

So if you need any shell tricks, like wildcard expansion or access to environment variables, use shell module.

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193