# Unwanted ansible-tmp in command

**URL:** <https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607>\
**Category:** Get Help\
**Tags:** gcp, ansible-devel, ansible-core\
**Created:** [January 14, 2025, 6:08pm UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607 "2025-01-14T18:08:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvzantvoort](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jvzantvoort/32/4968_2.png) [@jvzantvoort](https://forum.ansible.com/u/jvzantvoort)\
**Post date:** [January 14, 2025, 6:08pm UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607/1 "2025-01-14T18:08:46Z")

</div>

Unwanted ansible-tmp in command

I’m currently working on getting ansible to work with gcp in the scenario that direct ssh is not possible (which it is in my case). I’m using code provided in [How to tell Ansible to use GCP IAP tunneling - Xebia](https://xebia.com/blog/how-to-tell-ansible-to-use-gcp-iap-tunneling/)

During the execution of a ansible.builtin.file call I’m faced with an error:

```auto
gcloud compute ssh. ... -- -C /bin/sh -c 'rm -f -r ansible-tmp-1736873865.9504788-1510864-250879130520453=/tmp/ansible/ansible-tmp-1736873865.9504788-1510864-250879130520453/ > /dev/null 2>&1 && sleep 0'

```

Somehow the `ansible-tmp-.....=` gets shoved in front of the remote path. In the gcloud command this breaks functionality.

If anybody know a way to omit this without me hacking the wrapper scripts it would be much appreciated.

* * *

I expect the my problem to lies somewhere in `ansible/plugins/action/ __init__.py` the `_make_tmp_path` function that in turn calls `mkdtemp` in `ansible/plugins/shell/ __init__.py`

in the function the command is constructed in [ansible/lib/ansible/plugins/shell/\_\_init\_\_.py at v2.14.18 · ansible/ansible · GitHub](https://github.com/ansible/ansible/blob/v2.14.18/lib/ansible/plugins/shell/ __init__.py#L170-L179) . This makes a command like this

```auto
( umask 77 && mkdir -p "` echo /tmp/ansible `"&& mkdir "` echo /tmp/ansible/ansible-tmp-1736873865.9504788-1510864-250879130520453 `" && echo ansible-tmp-1736873865.9504788-1510864-250879130520453="` echo /tmp/ansible/ansible-tmp-1736873865.9504788-1510864-250879130520453 `" )

```

The reason I think this is because the `cleanup` function in action refers to the `tmpdir` property in `shell` which seems to be set by `_make_tmp_path` where it is a result of the `shell._generate_temp_dir_name` method. This seems to be a simple string passed from one function to another and the mangled string in the output looks much like the one I currently have trouble with.

Version info:

```auto
# molecule --version
molecule 6.0.3 using python 3.9 
    ansible:2.14.18
    default:6.0.3 from molecule

```

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [January 14, 2025, 7:23pm UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607/2 "2025-01-14T19:23:35Z")

</div>

The format of the data returned by [mkdtemp](https://github.com/ansible/ansible/blob/5623a386c1073f172d24b45f1b4582b092895e68/lib/ansible/plugins/shell/ __init__.py#L124) is `<basefile>=<tmp_path>/<basefile>` so that there is a string we can programatically look for to ensure we are splitting on the correct line of stdout.

This is handled in [\_make\_tmp\_path](https://github.com/ansible/ansible/blob/5623a386c1073f172d24b45f1b4582b092895e68/lib/ansible/plugins/action/ __init__.py#L504)

The fact that the result of `_make_tmp_path` hasn’t split the return, to only give the path back, makes it sound as though the `gcp-ssh-wrapper.sh` file is screwing with the data somehow. If you run with `-vvvv` you should see lines that start something like the following:

```auto
<hostname> SSH: EXEC ssh ... umask 77 && mkdir -p ...
<hostname> (0, b'ansible-tmp-1736882451.581056-82192-176146295572129=/home/sivel/.ansible/tmp/ansible-tmp-1736882451.581056-82192-176146295572129\n', b"...")

```

The first line being the command that attempts to get the remote tmpdir, and the 2nd the response that is then parsed.

From there, I guess you have to determine what is not being returned correctly, and why `_make_tmp_path` isn’t parsing it right.

---

<div class="post-metadata">

**Author:** ![jvzantvoort](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jvzantvoort/32/4968_2.png) [@jvzantvoort](https://forum.ansible.com/u/jvzantvoort)\
**Post date:** [January 14, 2025, 7:35pm UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607/3 "2025-01-14T19:35:25Z")

</div>

Make sense, I’ll dig into this and see if I can alter extend the output. Thanks.

---

<div class="post-metadata">

**Author:** ![jvzantvoort](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jvzantvoort/32/4968_2.png) [@jvzantvoort](https://forum.ansible.com/u/jvzantvoort)\
**Post date:** [January 15, 2025, 10:43am UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607/4 "2025-01-15T10:43:29Z")

</div>

Cleaned up the wrapper. Works now. Thanks!

---

<div class="post-metadata">

**Author:** ![rpavlik](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/rpavlik/32/7231_2.png) [@rpavlik](https://forum.ansible.com/u/rpavlik)\
**Post date:** [January 16, 2025, 5:43pm UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607/5 "2025-01-16T17:43:25Z")

</div>

can you post the revised wrapper, if the one on that post was insufficient?

---

<div class="post-metadata">

**Author:** ![jvzantvoort](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/jvzantvoort/32/4968_2.png) [@jvzantvoort](https://forum.ansible.com/u/jvzantvoort)\
**Post date:** [January 16, 2025, 8:17pm UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607/6 "2025-01-16T20:17:16Z")

</div>

This is my reference atm (before I started messing with it) [GitHub - jvzantvoort/ansible-collection-jdc-services](https://github.com/jvzantvoort/ansible-collection-jdc-services) I’ll update it with the remainder as soon as I can.

---

<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:** [February 15, 2025, 8:17pm UTC](https://forum.ansible.com/t/unwanted-ansible-tmp-in-command/39607/7 "2025-02-15T20:17:35Z")

</div>

Closed on February 15, 2025, 8:17pm UTC

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