Ansible Shell/命令模块 - "msg": "[Errno 2] 没有这样的文件或目录",

Rao*_*Rao 2 ansible

我想运行命令“ll /dev/disk/by-id/scsi-*”来获取scsi ID。我已经尝试过命令和 Shell 与变成:是的,但没有运气。

- name: Get ISCSI Id
  command: ll /dev/disk/by-id/scsi-*
  register: iscsiid
  become: yes
Run Code Online (Sandbox Code Playgroud)

错误:

    "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
}
Run Code Online (Sandbox Code Playgroud)

知道如何运行此命令吗?当我以 root 用户身份手动运行时,它可以工作。

谢谢,

che*_*huk 6

尝试使用 shell 模块而不是命令,也用像 'ls' 这样的 shell 命令替换 ll 别名 - 我试过并且它有效:

- name: test
  hosts: localhost
  tasks:
  - shell: ls -lstr /dev/disk/by-id/scsi-*
    register: iscsiid
    become: yes
  - debug:
      msg: "{{ iscsiid }}"
Run Code Online (Sandbox Code Playgroud)