Ansible Shell/Command Module - "msg": "[Errno 2] No such file or directory",

Viewed 15329

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,

1 Answers

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