# How do I get Ansible to load /snap/bin? I've tried everything, can't get it to work

**URL:** <https://forum.ansible.com/t/how-do-i-get-ansible-to-load-snap-bin-ive-tried-everything-cant-get-it-to-work/39752>\
**Category:** Get Help\
**Created:** [January 21, 2025, 7:55pm UTC](https://forum.ansible.com/t/how-do-i-get-ansible-to-load-snap-bin-ive-tried-everything-cant-get-it-to-work/39752 "2025-01-21T19:55:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeBradley](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/codebradley/32/7279_2.png) [@CodeBradley](https://forum.ansible.com/u/CodeBradley)\
**Post date:** [January 21, 2025, 7:55pm UTC](https://forum.ansible.com/t/how-do-i-get-ansible-to-load-snap-bin-ive-tried-everything-cant-get-it-to-work/39752/1 "2025-01-21T19:55:15Z")

</div>

tl;dr: How do I get my environment variables to load with `/snap/bin` added?

Here’s a test block that I added to my playbook to try and add `/snap/bin` to my PATH, which I want Ansible to load thereafter. I’ve seen this recommendation on a number of different forums; stack overflow, reddit, etc. Am I doing something wrong or is there a better approach to achieve this?

```auto
- name: Test path
  tags: test-path
  vars:
    path_var: "/snap/bin"
  block:
    - name: Add a path to system-wide $PATH.
      ansible.builtin.copy:
        dest: /etc/profile.d/custom-path.sh
        content: 'PATH=$PATH:{{ path_var }}'
        mode: "0644"

    - name: Dump path
      ansible.builtin.command: echo $PATH
      register: path_output

    - name: Dump path output
      ansible.builtin.debug:
        var: path_output.stdout

```

And here’s the output:

```auto
--- before: /etc/profile.d/custom-path.sh
+++ after: /etc/profile.d/custom-path.sh
@@ -1 +1 @@
-export PATH=$PATH:/snap/bin
\ No newline at end of file
+PATH=$PATH:/snap/bin

```

```auto
"path_output.stdout": "/home/brad/.pyenv/versions/3.13.1/bin:/home/brad/.pyenv/libexec:/home/brad/.pyenv/plugins/python-build/bin:/home/brad/.pyenv/plugins/pyenv-virtualenv/bin:/home/brad/.pyenv/plugins/pyenv-update/bin:/home/brad/.pyenv/plugins/pyenv-doctor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

```

I’ve tried adding export as well, still doesn’t work. I have this working in ZSH no problems because the same code, with export, is in my .profile file. It seems like it’s strictly an issue with /bin/sh which I don’t understand since this setup seem to work for everyone else?

I’m on Raspbian Bookworm and host machine is MacOS running ansible [core 2.18.1] and Python 3.13.1

I’m also confused because I don’t see anyone else having to add this to PATH when I’m reading through other microceph ansible roles? Not sure why. (Update: these aren’t working either)

Here’s a few examples:

> **[GitHub - pitabwire/ansible\_role\_microceph: Ansible role to bootstraps a ceph...](https://github.com/pitabwire/ansible_role_microceph/tree/main)**
>
> main

> **[GitHub - leothelyon17/ansible-role-microceph](https://github.com/leothelyon17/ansible-role-microceph)**
>
> Contribute to leothelyon17/ansible-role-microceph development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [January 21, 2025, 8:54pm UTC](https://forum.ansible.com/t/how-do-i-get-ansible-to-load-snap-bin-ive-tried-everything-cant-get-it-to-work/39752/2 "2025-01-21T20:54:33Z")

</div>

Try sourcing the profile – as far as I’m aware Ansible sets the `${PATH}` itself, it doesn’t get it from `/etc/profile`:

```yaml
    - name: Dump path
      ansible.builtin.shell: source /etc/profile && echo $PATH
      register: path_output

    - name: Dump path output
      ansible.builtin.debug:
        var: path_output.stdout

```

But perhaps I have misunderstood what you are trying to achieve?

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [January 21, 2025, 10:23pm UTC](https://forum.ansible.com/t/how-do-i-get-ansible-to-load-snap-bin-ive-tried-everything-cant-get-it-to-work/39752/3 "2025-01-21T22:23:56Z")

</div>

Ansible does batch (non interactive) logins and executions, it also prefers /bin/sh over other shells unless you specifically configure that as the executable/shell plugin. As for environment, you can use the `environment` keyword [Setting the remote environment — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_environment.html#setting-the-remote-environment) to add context to the task’s action’s execution
