Ansible Shell/Command Module - "msg": "[Errno 2] No such file or directory",
14,346
Try to use the shell module instead of command, also replace the ll alias with a shell command like 'ls' - i tried and it works :
- name: test
hosts: localhost
tasks:
- shell: ls -lstr /dev/disk/by-id/scsi-*
register: iscsiid
become: yes
- debug:
msg: "{{ iscsiid }}"
Related videos on Youtube
Author by
Rao
Updated on June 04, 2022Comments
-
Rao almost 2 years
I would like to run Command "ll /dev/disk/by-id/scsi-* " to get the scsi ID. I've tried command and Shell with become: yes, but no luck.
- name: Get ISCSI Id command: ll /dev/disk/by-id/scsi-* register: iscsiid become: yes
Error:
"changed": false, "cmd": "ll '/dev/disk/by-id/scsi-*'", "invocation": { "module_args": { "_raw_params": "ll /dev/disk/by-id/scsi-*", "_uses_shell": false, "argv": null, "chdir": null, "creates": null, "executable": null, "removes": null, "stdin": null, "warn": true } }, "msg": "[Errno 2] No such file or directory", "rc": 2 }
Any Idea how to run this command? It works whenI run manually as root user.
Thanks,
-
Tomislav Mikulin over 5 yearsthis isnt a problem with ansible or its moduels, the problem is the command itself "ll /dev/disk/by-id/scsi-"..., try running it with just "ll /dev/disk/"
-
mdaniel over 5 yearsI'd bet $1 it's because
ll
is a bash alias for/bin/ls -l
, and furthermore you cannot usecommand
with shell globs like that, as the fine manual very clearly states
-
-
Rao over 5 yearsThanks, it's working after changing the command from ll to ls -ltr. really appreciate your help.
-
chenchuk over 5 yearsif you are satisfied, please accept the answer. thanks