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

时间:2018-10-27 21:07:51

标签: 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

错误:

    "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
}

任何想法如何运行此命令?当我以root用户手动运行时,它可以工作。

谢谢

1 个答案:

答案 0 :(得分:1)

尝试使用shell模块而不是命令,也用ll命令之类的shell命令替换ll别名-我试过了,并且有效:

- name: test
  hosts: localhost
  tasks:
  - shell: ls -lstr /dev/disk/by-id/scsi-*
    register: iscsiid
    become: yes
  - debug:
      msg: "{{ iscsiid }}"