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 }}"
Share:
14,346

Related videos on Youtube

Rao
Author by

Rao

Updated on June 04, 2022

Comments

  • Rao
    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
      Tomislav Mikulin over 5 years
      this 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
      mdaniel over 5 years
      I'd bet $1 it's because ll is a bash alias for /bin/ls -l, and furthermore you cannot use command with shell globs like that, as the fine manual very clearly states
  • Rao
    Rao over 5 years
    Thanks, it's working after changing the command from ll to ls -ltr. really appreciate your help.
  • chenchuk
    chenchuk over 5 years
    if you are satisfied, please accept the answer. thanks