I don't have a silver bullet, but to avoid surprises with collections in
multiple locations, you can hard code the collections path in your
ansible.cfg.
We use 'ansible-core' (not 'ansible') from a python venv, and when setting
that up, we install the collections in there:

ANSIBLE_COLLECTIONS_PATH=$(python -c "import site;
print(site.getsitepackages()[0])") ansible-galaxy collection install -r
galaxy-requirements.yml

With this method you end up with the same structure as you would when pip
installing 'ansible', but without all the collection bloat that comes with
that.



On Tue, 19 Sept 2023 at 09:25, Romain Pelisse <bela...@redhat.com> wrote:

> Generally, I simply do a "$ rm -rf
> /home/user/.ansible/ansible_collections/" to force a collection refresh.
> You can also just remove like that, the collection causing issues.
>
> Another strategy is to force the installation, using --force, which will
> remove the old version and install the new latest one.
>
> That beings said, I don't think there is a risk of running the wrong
> version. The presence of different version is probably because one
> collection depends on version X and another one depends on version Y. So
> the first one will use X and the second will use Y.
>
> On Tue, Sep 19, 2023 at 1:41 AM 'Eric Jolley' via Ansible Project <
> ansible-project@googlegroups.com> wrote:
>
>> Hello All,
>>
>> I have an Ansible server with collections that are stored under a user
>> context in "/home/user/.ansible/ansible_collections/" in addition to the
>> collections for all users that are stored in
>> "/usr/lib/python3/dist-packages/ansible_collections/".  I found that there
>> are some duplicates of collections, such as "ansible.windows" that are
>> different versions.  In order to mitigate the risk of running playbooks
>> using the wrong version of a collection, I want to remove the collections
>> that are installed under a user context.
>>
>> Unfortunately, I found that there isn't a remove argument for
>> "ansible-galaxy collection".  And I didn't find anything in the Ansible
>> documentation or anything definitive in this Google group, nor doing Google
>> searches or ChatGPT. It is possible that deleting the specific folders
>> under /home/user/.ansible/ansible_collections/ would work.  But I don't
>> know if that could have unintended consequences.  So, I would like to get
>> some confirmation from anyone who has experience with this or knows where
>> it is documented.
>>
>> Does anyone know what the best practice is for removing installed
>> collections?
>>
>> Also, I have submitted an issue for the correct method to be documented
>> at:
>> https://docs.ansible.com/ansible/latest/collections_guide/index.html#using-ansible-collections.
>> It will probably take a while for that issue to be taken on and resolved
>> though.
>>
>> Best regards,
>> Eric
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Project" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to ansible-project+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/ansible-project/490f79e1-c2c2-48bf-99e4-fddea5bebe2an%40googlegroups.com
>> <https://groups.google.com/d/msgid/ansible-project/490f79e1-c2c2-48bf-99e4-fddea5bebe2an%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-project+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/CALuBA_oxDhdC03uRCAU3i8f%2BfAeJ038SsCiWa%2B5mL7qM1kuP9A%40mail.gmail.com
> <https://groups.google.com/d/msgid/ansible-project/CALuBA_oxDhdC03uRCAU3i8f%2BfAeJ038SsCiWa%2B5mL7qM1kuP9A%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAF8BbLbWdgCSwR%2B39Afm-xR3HXScRi%2BjspvVSxQ%2BS4Pf%2BCCwXg%40mail.gmail.com.

Reply via email to