Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mount module not mounting sshfs using state: mounted #67966

Closed
CodeSmolder opened this issue Mar 3, 2020 · 5 comments · Fixed by ansible-collections/ansible.posix#33
Closed
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. collection:ansible.posix collection Related to Ansible Collections work has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md P3 Priority 3 - Approved, No Time Limitation python3 support:community This issue/PR relates to code supported by the Ansible community. system System category

Comments

@CodeSmolder
Copy link

SUMMARY

Ansible mount module not mounting sshfs using state: mounted

ISSUE TYPE
  • Bug Report
COMPONENT NAME

Ansible mount

ANSIBLE VERSION
ansible 2.9.5
  config file = /Users/ap/ansible-workspace/ansible-st-server/ansible.cfg
  configured module search path = ['/Users/ap/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/ap/anaconda3/envs/ansible/lib/python3.7/site-packages/ansible
  executable location = /Users/ap/anaconda3/envs/ansible/bin/ansible
  python version = 3.7.5 (default, Oct 25 2019, 10:52:18) [Clang 4.0.1 (tags/RELEASE_401/final)]
CONFIGURATION
DEFAULT_HOST_LIST(/Users/ap/ansible-workspace/ansible-st-server/ansible.cfg) = ['/Users/ap/ansible-workspace/ansible-st-server/hosts']
HOST_KEY_CHECKING(/Users/ap/ansible-workspace/ansible-st-server/ansible.cfg) = False
INTERPRETER_PYTHON(/Users/ap/ansible-workspace/ansible-st-server/ansible.cfg) = /usr/bin/python3
RETRY_FILES_ENABLED(/Users/ap/ansible-workspace/ansible-st-server/ansible.cfg) = False
OS / ENVIRONMENT

Target OS is Ubuntu 18.04.4 LTS

STEPS TO REPRODUCE

If you run the following code within a task, the fstab entry will be written correctly but it will not be mounted as expected. It works if root user mounts manually ( with mount /home/borg/backups-remote) using a ssh connection to the server.

- name: Create dedicated user for borg backup
  user:
    name: borg
    comment: Dedicated user for borg backup
    password_lock: yes
    shell: /bin/bash
  register: borg_user
- name: Adding fstab entry for borg remote mount point
  mount:
    path: /home/borg/backups-remote
    src: borg@myserver.com:/users/borg
    fstype: fuse.sshfs
    opts: "defaults,allow_other,_netdev,idmap=user,follow_symlinks,identityfile=/home/borg/.ssh/id_rsa,allow_other,default_permissions,uid={{ borg_user.uid }},gid={{ borg_user.group }}"
    state: mounted
  register: backup_remote
EXPECTED RESULTS

Entry added to fstab (this works) and state mounted (this works not).

ACTUAL RESULTS
task path: /Users/ap/ansible-workspace/ansible-st-server/roles/docker_host_server/tasks/init_borg_backup_user.yml:48
<myserver.com> ESTABLISH SSH CONNECTION FOR USER: root
<myserver.com> SSH: EXEC sshpass -d59 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/Users/ap/.ansible/cp/e64dcd018c myserver.com '/bin/sh -c '"'"'echo ~root && sleep 0'"'"''
<myserver.com> (0, b'/root\n', b'OpenSSH_7.9p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 48: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 17203\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<myserver.com> ESTABLISH SSH CONNECTION FOR USER: root
<myserver.com> SSH: EXEC sshpass -d59 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/Users/ap/.ansible/cp/e64dcd018c myserver.com '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456 `" && echo ansible-tmp-1583243356.797665-113017624172456="` echo /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456 `" ) && sleep 0'"'"''
<myserver.com> (0, b'ansible-tmp-1583243356.797665-113017624172456=/root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456\n', b'OpenSSH_7.9p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 48: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 17203\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
Using module file /Users/ap/anaconda3/envs/ansible/lib/python3.7/site-packages/ansible/modules/system/mount.py
<myserver.com> PUT /Users/ap/.ansible/tmp/ansible-local-17190njygosda/tmpllr8128c TO /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456/AnsiballZ_mount.py
<myserver.com> SSH: EXEC sshpass -d59 sftp -o BatchMode=no -b - -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/Users/ap/.ansible/cp/e64dcd018c '[myserver.com]'
<myserver.com> (0, b'sftp> put /Users/ap/.ansible/tmp/ansible-local-17190njygosda/tmpllr8128c /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456/AnsiballZ_mount.py\n', b'OpenSSH_7.9p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 48: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 17203\r\ndebug3: mux_client_request_session: session request sent\r\ndebug2: Remote version: 3\r\ndebug2: Server supports extension "posix-rename@openssh.com" revision 1\r\ndebug2: Server supports extension "statvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "fstatvfs@openssh.com" revision 2\r\ndebug2: Server supports extension "hardlink@openssh.com" revision 1\r\ndebug2: Server supports extension "fsync@openssh.com" revision 1\r\ndebug3: Sent message fd 3 T:16 I:1\r\ndebug3: SSH_FXP_REALPATH . -> /root size 0\r\ndebug3: Looking up /Users/ap/.ansible/tmp/ansible-local-17190njygosda/tmpllr8128c\r\ndebug3: Sent message fd 3 T:17 I:2\r\ndebug3: Received stat reply T:101 I:2\r\ndebug1: Couldn\'t stat remote file: No such file or directory\r\ndebug3: Sent message SSH2_FXP_OPEN I:3 P:/root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456/AnsiballZ_mount.py\r\ndebug3: Sent message SSH2_FXP_WRITE I:4 O:0 S:32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 4 32768 bytes at 0\r\ndebug3: Sent message SSH2_FXP_WRITE I:5 O:32768 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:6 O:65536 S:32768\r\ndebug3: Sent message SSH2_FXP_WRITE I:7 O:98304 S:15223\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 5 32768 bytes at 32768\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 6 32768 bytes at 65536\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: In write loop, ack for 7 15223 bytes at 98304\r\ndebug3: Sent message SSH2_FXP_CLOSE I:4\r\ndebug3: SSH2_FXP_STATUS 0\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<myserver.com> ESTABLISH SSH CONNECTION FOR USER: root
<myserver.com> SSH: EXEC sshpass -d59 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/Users/ap/.ansible/cp/e64dcd018c myserver.com '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456/ /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456/AnsiballZ_mount.py && sleep 0'"'"''
<myserver.com> (0, b'', b'OpenSSH_7.9p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 48: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 17203\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
<myserver.com> ESTABLISH SSH CONNECTION FOR USER: root
<myserver.com> SSH: EXEC sshpass -d59 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/Users/ap/.ansible/cp/e64dcd018c -tt myserver.com '/bin/sh -c '"'"'/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456/AnsiballZ_mount.py && sleep 0'"'"''
<myserver.com> (0, b'\r\n{"changed": true, "name": "/home/borg/backups-remote", "opts": "defaults,allow_other,_netdev,idmap=user,follow_symlinks,identityfile=/home/borg/.ssh/id_rsa,allow_other,default_permissions,uid=1001,gid=1001", "dump": "0", "passno": "0", "fstab": "/etc/fstab", "src": "borg@myserver.com:/users/borg", "fstype": "fuse.sshfs", "invocation": {"module_args": {"path": "/home/borg/backups-remote", "src": "borg@myserver.com:/users/borg", "fstype": "fuse.sshfs", "opts": "defaults,allow_other,_netdev,idmap=user,follow_symlinks,identityfile=/home/borg/.ssh/id_rsa,allow_other,default_permissions,uid=1001,gid=1001", "state": "mounted", "boot": true, "backup": false, "dump": null, "fstab": null, "passno": null}}}\r\n', b'OpenSSH_7.9p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 48: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 17203\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\nShared connection to myserver.com closed.\r\n')
<myserver.com> ESTABLISH SSH CONNECTION FOR USER: root
<myserver.com> SSH: EXEC sshpass -d59 ssh -vvv -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o 'User="root"' -o ConnectTimeout=10 -o ControlPath=/Users/ap/.ansible/cp/e64dcd018c myserver.com '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1583243356.797665-113017624172456/ > /dev/null 2>&1 && sleep 0'"'"''
<myserver.com> (0, b'', b'OpenSSH_7.9p1, LibreSSL 2.7.3\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 48: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 17203\r\ndebug3: mux_client_request_session: session request sent\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Received exit status from master 0\r\n')
changed: [myserver.com] => {
    "changed": true,
    "dump": "0",
    "fstab": "/etc/fstab",
    "fstype": "fuse.sshfs",
    "invocation": {
        "module_args": {
            "backup": false,
            "boot": true,
            "dump": null,
            "fstab": null,
            "fstype": "fuse.sshfs",
            "opts": "defaults,allow_other,_netdev,idmap=user,follow_symlinks,identityfile=/home/borg/.ssh/id_rsa,allow_other,default_permissions,uid=1001,gid=1001",
            "passno": null,
            "path": "/home/borg/backups-remote",
            "src": "borg@myserver.com:/users/borg",
            "state": "mounted"
        }
    },
    "name": "/home/borg/backups-remote",
    "opts": "defaults,allow_other,_netdev,idmap=user,follow_symlinks,identityfile=/home/borg/.ssh/id_rsa,allow_other,default_permissions,uid=1001,gid=1001",
    "passno": "0",
    "src": "borg@myserver.com:/users/borg"
}
@ansibot
Copy link
Contributor

ansibot commented Mar 3, 2020

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Mar 3, 2020

cc @jtyr
click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. system System category labels Mar 3, 2020
@samdoran samdoran added needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Mar 5, 2020
@patrakov
Copy link

patrakov commented Mar 8, 2020

This would be fixed by #65869

@ansibot
Copy link
Contributor

ansibot commented Mar 24, 2020

Files identified in the description:
None

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added has_pr This issue has an associated PR. and removed module This issue/PR relates to a module. labels Mar 24, 2020
@ansibot
Copy link
Contributor

ansibot commented Apr 1, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added the module This issue/PR relates to a module. label Apr 1, 2020
@ansibot ansibot added collection Related to Ansible Collections work collection:ansible.posix needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md support:community This issue/PR relates to code supported by the Ansible community. and removed support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Apr 24, 2020
Akasurde pushed a commit to Akasurde/ansible.posix that referenced this issue May 29, 2020
…ansible#61752)"

This reverts part of ansible commit 72023d7.

The immediate reason is that it breaks mounts where src is not a path.
Examples of such mounts are network-based filesystems such as nfs, cifs,
glusterfs, ceph, virtual filesystems such as tmpfs or overlayfs, and
also UUID-based mounts. It is too hard to come with an exhaustive list,
especially if we take non-Linux systems into account, so don't even try.

Additionally, it did not really fix the issue (ansible/ansible#59183) that
it intended to fix, because the mount could fail but leave a non-working
fstab entry for reasons other than non-existing src path.

Fixes: ansible/ansible#65855
Fixes: ansible/ansible#67588
Fixes: ansible/ansible#67966
Akasurde pushed a commit to Akasurde/ansible.posix that referenced this issue May 29, 2020
…ansible#61752)"

This reverts part of ansible commit 72023d7.

The immediate reason is that it breaks mounts where src is not a path.
Examples of such mounts are network-based filesystems such as nfs, cifs,
glusterfs, ceph, virtual filesystems such as tmpfs or overlayfs, and
also UUID-based mounts. It is too hard to come with an exhaustive list,
especially if we take non-Linux systems into account, so don't even try.

Additionally, it did not really fix the issue (ansible/ansible#59183) that
it intended to fix, because the mount could fail but leave a non-working
fstab entry for reasons other than non-existing src path.

Restore fstab and remove the mount point after a failed mount

Add a reminder that not only devices can be mounted

Fixes: ansible/ansible#65855
Fixes: ansible/ansible#67588
Fixes: ansible/ansible#67966

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Akasurde pushed a commit to Akasurde/ansible.posix that referenced this issue May 29, 2020
…ansible#61752)"

This reverts part of ansible commit 72023d7.

The immediate reason is that it breaks mounts where src is not a path.
Examples of such mounts are network-based filesystems such as nfs, cifs,
glusterfs, ceph, virtual filesystems such as tmpfs or overlayfs, and
also UUID-based mounts. It is too hard to come with an exhaustive list,
especially if we take non-Linux systems into account, so don't even try.

Additionally, it did not really fix the issue (ansible/ansible#59183) that
it intended to fix, because the mount could fail but leave a non-working
fstab entry for reasons other than non-existing src path.

Restore fstab and remove the mount point after a failed mount

Add a reminder that not only devices can be mounted

Fixes: ansible/ansible#65855
Fixes: ansible/ansible#67588
Fixes: ansible/ansible#67966

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
maxamillion pushed a commit to ansible-collections/ansible.posix that referenced this issue May 29, 2020
…ansible#61752)" (#33)

This reverts part of ansible commit 72023d7.

The immediate reason is that it breaks mounts where src is not a path.
Examples of such mounts are network-based filesystems such as nfs, cifs,
glusterfs, ceph, virtual filesystems such as tmpfs or overlayfs, and
also UUID-based mounts. It is too hard to come with an exhaustive list,
especially if we take non-Linux systems into account, so don't even try.

Additionally, it did not really fix the issue (ansible/ansible#59183) that
it intended to fix, because the mount could fail but leave a non-working
fstab entry for reasons other than non-existing src path.

Restore fstab and remove the mount point after a failed mount

Add a reminder that not only devices can be mounted

Fixes: ansible/ansible#65855
Fixes: ansible/ansible#67588
Fixes: ansible/ansible#67966

Signed-off-by: Alexander E. Patrakov <patrakov@gmail.com>
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>

Co-authored-by: Alexander E. Patrakov <patrakov@gmail.com>
@ansible ansible locked and limited conversation to collaborators Jun 26, 2020
@sivel sivel removed the needs_verified This issue needs to be verified/reproduced by maintainer label Feb 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. collection:ansible.posix collection Related to Ansible Collections work has_pr This issue has an associated PR. module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md P3 Priority 3 - Approved, No Time Limitation python3 support:community This issue/PR relates to code supported by the Ansible community. system System category
Projects
None yet
5 participants