ansible-collections / ansible.posix

Ansible Collection for Posix
Other
156 stars 151 forks source link

ansible.posix.mount on macOS 10.15.7 cannot mount ISO #107

Open NathanDotTo opened 3 years ago

NathanDotTo commented 3 years ago
SUMMARY

The CLI commands to mount an ISO with macOS 10.15.7 are illustrated below:

$ hdiutil attach -nomount /tmp/ubuntu-20.04.1-live-server-amd64.iso 
/dev/disk3              Apple_partition_scheme          
/dev/disk3s1            Apple_partition_map             
/dev/disk3s2            Apple_HFS                       
$ mount -t cd9660 /dev/disk3 iso                                   
$ cd iso
$ ls
EFI         boot            dists           isolinux        pics            preseed
README.diskdefines  casper          install         md5sum.txt      pool            ubuntu

Note that this is a two step process. Also note the type of cd9660. The type of cd9660 is not documented here:

https://docs.ansible.com/ansible/latest/collections/ansible/posix/mount_module.html

An equivalent in Ansible would appear to be:

    - name: Mount Ubuntu ISO
      ansible.posix.mount:
        path: "iso"
        src: src="/tmp/ubuntu-20.04.1-live-server-amd64.iso"
        fstype: cd9660
        opts: auto
        state: mounted

That results in:

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "backup": false,
            "boot": true,
            "dump": null,
            "fstab": null,
            "fstype": "cd9660",
            "opts": "auto",
            "passno": null,
            "path": "/tmp/ubuntu20/iso",
            "src": "src=\"/tmp/ubuntu-20.04.1-live-server-amd64.iso\"",
            "state": "mounted"
        }
    },
    "msg": "Error mounting /tmp/ubuntu20/iso: mount_cd9660: No such file or directory\nmount: /private/tmp/ubuntu20/iso failed with 1\n"
}

I suspect that this is because the hdiutil stage illustrated above is not executed.

ISSUE TYPE
COMPONENT NAME

ansible.posix.mount

ANSIBLE VERSION
ansible 2.9.13
  config file = None
  configured module search path = ['/Users/xxx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/homebrew/Cellar/ansible/2.9.13_1/libexec/lib/python3.9/site-packages/ansible
  executable location = /usr/local/homebrew/bin/ansible
  python version = 3.9.0 (default, Oct 28 2020, 16:23:50) [Clang 12.0.0 (clang-1200.0.32.21)]
CONFIGURATION

Note that there was no output from ansible-config dump --only-changed.

OS / ENVIRONMENT

macOS 10.15.7 (19H2)

STEPS TO REPRODUCE

1 - Have a ISO file in /tmp, e.g. /tmp/ubuntu-20.04.1-live-server-amd64.iso 2 - Create a directory iso, e.g. mkdir iso 2 - Run the playbook below, e.g. sudo ansible-playbook -vvv mount.yml

    - name: Mount Ubuntu ISO
      ansible.posix.mount:
        path: "iso"
        src: src="/tmp/ubuntu-20.04.1-live-server-amd64.iso"
        fstype: cd9660
        opts: auto
        state: mounted
EXPECTED RESULTS

I expect to see the ISO mounted, as it is with the commands illustrated in the summary above.

ACTUAL RESULTS

The mount fails with file not found.

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "backup": false,
            "boot": true,
            "dump": null,
            "fstab": null,
            "fstype": "cd9660",
            "opts": "auto",
            "passno": null,
            "path": "/tmp/ubuntu20/iso",
            "src": "src=\"/tmp/ubuntu-20.04.1-live-server-amd64.iso\"",
            "state": "mounted"
        }
    },
    "msg": "Error mounting /tmp/ubuntu20/iso: mount_cd9660: No such file or directory\nmount: /private/tmp/ubuntu20/iso failed with 1\n"
}

For the purposes of compare and contrast between macOS and Ubuntu, I have reduced the playbook to the following structure, and I provide examples of execution on macOS, and then Ubuntu.

   - name: Mount Ubuntu ISO
      action: mount name="{{ WorkingDir }}/iso" src="{{ TempDir }}/{{ UbuntuISO }}" opts=loop fstype=iso9660 state=mounted

macOS 10.15.7:

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "backup": false,
            "boot": true,
            "dump": null,
            "fstab": null,
            "fstype": "iso9660",
            "name": "/tmp/ubuntu20/iso",
            "opts": "loop",
            "passno": null,
            "path": "/tmp/ubuntu20/iso",
            "src": "/tmp/ubuntu-20.04.1-live-server-amd64.iso",
            "state": "mounted"
        }
    },
    "msg": "Error mounting /tmp/ubuntu20/iso: mount: exec /Library/Filesystems/iso9660.fs/Contents/Resources/mount_iso9660 for /private/tmp/ubuntu20/iso: No such file or directory\nmount: /private/tmp/ubuntu20/iso failed with 72\n"
}

Ubuntu 20.04.1

changed: [localhost] => {
    "changed": true,
    "dump": "0",
    "fstab": "/etc/fstab",
    "fstype": "iso9660",
    "invocation": {
        "module_args": {
            "backup": false,
            "boot": true,
            "dump": null,
            "fstab": null,
            "fstype": "iso9660",
            "name": "/tmp/ubuntu20/iso",
            "opts": "loop",
            "passno": null,
            "path": "/tmp/ubuntu20/iso",
            "src": "/tmp/ubuntu-20.04.1-live-server-amd64.iso",
            "state": "mounted"
        }
    },
    "name": "/tmp/ubuntu20/iso",
    "opts": "loop",
    "passno": "0",
    "src": "/tmp/ubuntu-20.04.1-live-server-amd64.iso"
}
quidame commented 3 years ago

Hi @NathanDotTo , it seems to me there are some lack of consistency in the examples provided in the report. In the first case, you use:

        path: "iso"
        src: src="/tmp/ubuntu-20.04.1-live-server-amd64.iso"
        fstype: cd9660

then, mount_cd9660: No such file or directory. I guess that the mount helper mount_cd9660 is unable to find the iso image at this location: src="/tmp/ubuntu-20.04.1-live-server-amd64.iso". Why this src= prepending the path ?

In the second case, the values provided are:

        path: "/tmp/ubuntu20/iso"
        src: "/tmp/ubuntu-20.04.1-live-server-amd64.iso"
        fstype: iso9660

and then, mount: exec /Library/Filesystems/iso9660.fs/Contents/Resources/mount_iso9660 for /private/tmp/ubuntu20/iso: No such file or directory. This time, the mount command complains that there is no helper command for iso9660 filesystem type.

Could you please retry with your last playbook (the one that is working on Ubuntu), and adjust fstype=cd9660 for Mac OS X ?

quidame commented 3 years ago

hmmm... I think this is not a bug. Or at least this report needs more info, since the two examples provided fail because each embeds a value error (once for src, once for fstype).

# First failure reported with:
- name: Mount Ubuntu ISO
  ansible.posix.mount:
    path: "iso"
    src: src="/tmp/ubuntu-20.04.1-live-server-amd64.iso"  # no such file or directory
    fstype: "cd9660"                                      # valid fstype on Mac OS X
    opts: "auto"
    state: mounted

and:

# Second failure reported with:
- name: Mount Ubuntu ISO
  ansible.posix.mount:
    path: "/tmp/ubuntu20/iso"
    src: "/tmp/ubuntu-20.04.1-live-server-amd64.iso"  # this time, the file exists
    fstype: "iso9660"                                 # invalid fstype on Mac OS X
    opts: "loop"
    state: mounted

Also, opts change between examples, making more difficult to follow what happens (it's easier to compare things that can be compared, rather than modifying any parameter randomly).

Again, this must be tested on Mac OS X with the proper parameter values (valid fstype cd9660 rather than iso9660, and a valid file path, not starting with a typo) before stating there is a bug here. What I see here is that the module fails as expected, nothing more.

@NathanDotTo , could you try again, please ? Or someone else ?

Akasurde commented 3 years ago

@NathanDotTo Could you please try @quidame's suggestion and let us know if it works?

Thanks,

needs_info

NathanDotTo commented 3 years ago

Apologies for the delay. This is part of a project to which I am unable to dedicate time now. We plan to have a person full time on this project from April.

On 24 Mar 2021, at 09:04, Abhijeet Kasurde @.***> wrote:

@NathanDotTo https://github.com/NathanDotTo Could you please try @quidame https://github.com/quidame's suggestion and let us know if it works?

Thanks,

needs_info

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ansible-collections/ansible.posix/issues/107#issuecomment-805592146, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGFXFR67PYGFWGVB7XUI73TFGMKXANCNFSM4TDSQPKA.

quidame commented 3 years ago

@NathanDotTo ping ?

aashishthite commented 2 years ago

I followed @quidame 's suggestions. I now get

    "changed": false,
    "invocation": {
        "module_args": {
            "backup": false,
            "boot": true,
            "dump": null,
            "fstab": null,
            "fstype": "cd9660",
            "opts": "ro,noauto",
            "passno": null,
            "path": "/tmp/ubuntu20/iso",
            "src": "/tmp/ubuntu-20.04.3-live-server-amd64.iso",
            "state": "mounted"
        }
    },
    "msg": "Error mounting /tmp/ubuntu20/iso: mount_cd9660: Block device required\nmount: /private/tmp/ubuntu20/iso failed with 1\n"
}