# Ansible.posix.mount opts with password not working

**URL:** <https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135>\
**Category:** Get Help\
**Created:** [April 24, 2024, 7:49pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135 "2024-04-24T19:49:20Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [April 24, 2024, 7:49pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/1 "2024-04-24T19:49:20Z")

</div>

When using the mount module with the below code I’m facing an issue when the password has a double quote in it. I’m not sure if its the module or ansible that is auto escaping it with a single slash.

```auto
- name: "Mount {{ common_cifs_root }}"
  ansible.posix.mount:
    src: "{{ common_cifs_root }}"
    path: "{{ common_mount_folder }}"
    opts: "noserverino,dom={{ common_ad_domain }},username={{ common_ad_username }},password={{ common_ad_password }}"
    state: ephemeral
    fstype: "{{ common_fs_type }}"

```

The first line is the password, the 2nd is what ansible is sending. The mount command doesn’t like that, if I run the command manually with the password as is it works.

`~*ACE=!t#,26F3"16a` - Password

`~*ACE=!t#,26F3\"16a` - Password set by ansible || moudle

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 24, 2024, 8:30pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/2 "2024-04-24T20:30:20Z")

</div>

Can you show us the error output? I actually would expect the double-quotes to be escaped depending on the context.

---

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [April 24, 2024, 8:36pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/3 "2024-04-24T20:36:05Z")

</div>

This is with -vvvv set.

```auto
fatal: [node1]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "backup": false,
            "boot": true,
            "dump": "0",
            "fstab": null,
            "fstype": "cifs",
            "opts": "noserverino,dom=aasp,username=myuser,password=~*ACE=!t#,26F3\"16a",
            "passno": "0",
            "path": "/tmp/cert_test",
            "src": "//nas/tutility/users/myuser/was_certs",
            "state": "ephemeral"
        }
    },
    "msg": "Error mounting /tmp/cert_test: mount error(13): Permission denied\nRefer to the mount.cifs(8) manual page (e.g. man mount.cifs)\n"

```

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 24, 2024, 8:44pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/4 "2024-04-24T20:44:08Z")

</div>

Okay, so the escaped quotes there is because it _has to be_ for the json returned to valid. It shouldn’t be escaped by the module when executed.

Are you running this with elevated permissions? Either as root or with `become: true`?

---

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [April 24, 2024, 8:45pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/5 "2024-04-24T20:45:23Z")

</div>

With become set yes. Not as root.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 24, 2024, 9:00pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/6 "2024-04-24T21:00:48Z")

</div>

Well, you could try creating a credentials file first and passing `credentials=<filename>` on the mount task instead, or you could try setting `PASSWD` as an environment variable. It might be that the `!` is the problem and only `~*ACE=` is being treated as the password; while we’re just not seeing the `!t#,26F3"16a: event not found` error for some reason.

I.e.

```yaml
- name: "Mount {{ common_cifs_root }}"
  ansible.posix.mount:
    src: "{{ common_cifs_root }}"
    path: "{{ common_mount_folder }}"
    opts: "noserverino,dom={{ common_ad_domain }},username={{ common_ad_username }}"
    state: ephemeral
    fstype: "{{ common_fs_type }}"
  environment:
    PASSWD: "{{ common_ad_password }}"

```

I’m also wondering if you need `sec=ntlmv2` or `vers=3`, but I think you would get a different error if that were the case.

---

<div class="post-metadata">

**Author:** ![dpowell](https://avatars.discourse-cdn.com/v4/letter/d/e95f7d/32.png) [@dpowell](https://forum.ansible.com/u/dpowell)\
**Post date:** [April 24, 2024, 9:16pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/7 "2024-04-24T21:16:08Z")

</div>

I tried the sec/vers with no luck but the code block as is worked. Thanks for the suggestion.

---

<div class="post-metadata">

**Author:** ![Denney-tech](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/denney-tech/32/1556_2.png) [@Denney-tech](https://forum.ansible.com/u/Denney-tech)\
**Post date:** [April 24, 2024, 9:42pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/8 "2024-04-24T21:42:17Z")

</div>

> [@dpowell](#):
>
> the code block as is worked. Thanks for the suggestion.

You’re welcome, glad that worked.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 24, 2024, 9:42pm UTC](https://forum.ansible.com/t/ansible-posix-mount-opts-with-password-not-working/5135/9 "2024-05-24T21:42:26Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
