# Ansible-galaxy command ignores token set in environment

**URL:** <https://forum.ansible.com/t/ansible-galaxy-command-ignores-token-set-in-environment/2012>\
**Category:** Get Help\
**Tags:** galaxy, galaxy-ng\
**Created:** [October 28, 2023, 7:06am UTC](https://forum.ansible.com/t/ansible-galaxy-command-ignores-token-set-in-environment/2012 "2023-10-28T07:06:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shaps](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shaps/32/1356_2.png) [@Shaps](https://forum.ansible.com/u/Shaps)\
**Post date:** [October 28, 2023, 7:06am UTC](https://forum.ansible.com/t/ansible-galaxy-command-ignores-token-set-in-environment/2012/1 "2023-10-28T07:06:34Z")

</div>

Hey,  
at work we are migrating to using an internal galaxy server ( yes it’s the paid RH version, but this question is not relevant to the product itself ).

While testing the config, I ended up in a big rabbit hole because I was trying to **only** set the **url** in the config file and set the token as a separate file, then use `ANSIBLE_GALAXY_TOKEN_PATH` in the environment to set the API token.  
After a bit of looking around in the code, I noticed that if `token` is not set in the `ansible.cfg` file, along with the URL, it is ignored entirely.

I’m sure there is a reason behind this but I cannot understand why that’s the case. Can I please have some context for this decision?

I have a couple of ideas on how to get this to work and I’m happy to raise a PR as usual.

Hopefully the above makes sense. Below is a sample of the setup:

```auto
[galaxy]
server_list = rh-certified_repo

[galaxy_server.rh-certified_repo]
url=<internal_galaxy_url>/api/galaxy/content/rh-certified/

```

The token file would look something like the below and the respective env var points to it:

```auto
token: <token>

```

---

<div class="post-metadata">

**Author:** ![xolyu](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/xolyu/32/1360_2.png) [@xolyu](https://forum.ansible.com/u/xolyu)\
**Post date:** [October 30, 2023, 9:13am UTC](https://forum.ansible.com/t/ansible-galaxy-command-ignores-token-set-in-environment/2012/2 "2023-10-30T09:13:17Z")

</div>

Did you try to save the `galaxy_token` file under the default path?

This worked for me with _ansible-galaxy [core 2.15.5]_.

Default path: `ANSIBLE_HOME/galaxy_token`  
without special configuration this should be: `~/.ansible/galaxy_token`

I have also been able to successfully load the token via environment variable `ANSIBLE_GALAXY_TOKEN_PATH` as well as by definition as `token_path` in _ansible.cfg_.

Have you already looked at the verbose output with `-vvvvv`?

---

<div class="post-metadata">

**Author:** ![Shaps](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shaps/32/1356_2.png) [@Shaps](https://forum.ansible.com/u/Shaps)\
**Post date:** [October 30, 2023, 10:37am UTC](https://forum.ansible.com/t/ansible-galaxy-command-ignores-token-set-in-environment/2012/3 "2023-10-30T10:37:18Z")

</div>

Hey @xolyu,  
Thanks for your reply.

Yes I already tried all that, the galaxy/core version is the same.  
I have no issue if I **only** define the `ANSIBLE_GALAXY_TOKEN_PATH` variable, the issue comes up when I define the galaxy URL in the config file and the token path as a env variable.

I’m confident if you try using the config in the original post it won’t work.  
Just FYI, this is the output ( a shorter version as there’s plenty of non relevant info ) of the `-vvvvv` output

```auto
❯ ansible-galaxy collection install -vvvv ansible.controller:4.2.0 --force
ansible-galaxy [core 2.15.5]
  config file = /Users/andrea_tartaglia/Documents/code/roles/aap_organization/ansible.cfg
  configured module search path = ['/Users/andrea_tartaglia/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/andrea_tartaglia/.pyenv/versions/3.10.3/lib/python3.10/site-packages/ansible
  ansible collection location = /Users/andrea_tartaglia/.ansible/collections:/usr/share/ansible/collections
  executable location = /Users/andrea_tartaglia/.pyenv/versions/3.10.3/bin/ansible-galaxy
  python version = 3.10.3 (main, May 4 2022, 17:28:50) [Clang 13.1.6 (clang-1316.0.21.2.3)] (/Users/andrea_tartaglia/.pyenv/versions/3.10.3/bin/python3.10)
  jinja version = 3.1.2
  libyaml = True
Using /Users/andrea_tartaglia/Documents/code/roles/aap_organization/ansible.cfg as config file
Starting galaxy collection install process

[...]

Process install dependency map
Initial connection to galaxy_server: https://<galaxy_url>/api/galaxy/content/rh-certified/
Found API version 'v3' with Galaxy server rh-certified_repo (https://<galaxy_url>/api/galaxy/content/rh-certified/)
Opened /Users/andrea_tartaglia/.ansible/galaxy_token
Calling Galaxy at https://<galaxy_url>/api/galaxy/content/rh-certified/v3/collections/ansible/controller/
ERROR! Error when getting the collection info for ansible.controller from rh-certified_repo (https://<galaxy_url>/api/galaxy/content/rh-certified/) (HTTP Code: 403, Message: Authentication credentials were not provided. Code: not_authenticated)

```

```auto
❯ echo $ANSIBLE_GALAXY_TOKEN_PATH
~/.ansible/galaxy_token

```

---

<div class="post-metadata">

**Author:** ![hugotomasi](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugotomasi/32/10423_2.png) [@hugotomasi](https://forum.ansible.com/u/hugotomasi)\
**Post date:** [March 3, 2026, 4:12pm UTC](https://forum.ansible.com/t/ansible-galaxy-command-ignores-token-set-in-environment/2012/4 "2026-03-03T16:12:57Z")

</div>

Hi,

Did you end up finding a solution for this ? It seems like I actually have this same issue right now ☹

Best regards.

---

<div class="post-metadata">

**Author:** ![Shaps](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shaps/32/1356_2.png) [@Shaps](https://forum.ansible.com/u/Shaps)\
**Post date:** [March 5, 2026, 7:56am UTC](https://forum.ansible.com/t/ansible-galaxy-command-ignores-token-set-in-environment/2012/5 "2026-03-05T07:56:38Z")

</div>

Hi @hugotomasi ,  
Unfortunately not. I just ended up adding both url and token in the config file.
