Score:0

Wildcard doesn't work in ansible shell command

cz flag

The shell command doesn't expand wildcard when running ansible module through powershell.

If I remove the wildcard and specify the version number it works 'rabbitmq_server-3.9.3'.

Any suggestion on how to make this work with wildcard?

Yaml code:

  - name: Check if RabbitMQ is already installed
    shell: "\"/cygdrive/c/Program\ Files/RabbitMQ\ Server/rabbitmq_server-*/sbin/rabbitmq-service.bat\" status"
    ignore_errors: true
    register: RabbitMQ_install_status

Error:

'C:\cygwin\bin\bash.exe -c ansible-playbook test.yml':

TASK [Check if RabbitMQ is already installed] **************************************************************************fatal: [localhost]: FAILED! => {"changed": true, "cmd": "\"/cygdrive/c/Program Files/RabbitMQ Server/rabbitmq_server-*/sbin/rabbitmq-service.bat\" status", "delta": "0:00:00.042184", "end": "2021-08-16 13:43:52.066236", "msg": "non-zero return code", "rc": 127, "start": "2021-08-16 13:43:52.024052", "stderr": "/bin/sh: /cygdrive/c/Program Files/RabbitMQ Server/rabbitmq_server-*/sbin/rabbitmq-service.bat: No such file or directory", "stderr_lines": ["/bin/sh: /cygdrive/c/Program Files/RabbitMQ Server/rabbitmq_server-*/sbin/rabbitmq-service.bat: No such file or directory"], "stdout": "", "stdout_lines": []}
...ignoring
in flag
The `shell` module is for Unix systems. With PowerShell and Windows you need to use `win_shell`.
Score:0
cn flag

you need .*

"/cygdrive/c/Program\ Files/RabbitMQ\ Server/rabbitmq_server-.*/sbin/rabbitmq-service.bat"

Score:0
cz flag

The shell doesn't expand the wildcard because you have put it in quotes. Wildcard expansion is not done in either single or double quotes.

\"/cygdrive/c/Program\ Files/RabbitMQ\ Server/rabbitmq_server-*/sbin/rabbitmq-service.bat\"

Presumably you have done this to escape the spaces in the path.

Try quoting only the part of the path that needs to be quoted.

\"/cygdrive/c/Program\ Files/RabbitMQ\ Server\"/rabbitmq_server-*/sbin/rabbitmq-service.bat
##                                           ##
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.