Community.general.ansible_galaxy_install Not Using Correct PATH - But This May Not Be The Actual Problem

Hi All,

Bare with me, please, this is slightly complex.

I’m trying to use community.general.ansible_galaxy_install inside a playbook to ensure that the remote host (which is an(other) Ansible Control Node (ACN)) has a number of Collections installed.

Both my current ACN and the remore ACN are Rocky Linux hosts. Rocky Linux does not place /usr/local/bin into the default PATH (only /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin). Of course, where is ansible-galaxy (and the other ansible* tools) installed? That’s right, /usr/local/bin.

So, I’ve modified my systems’ /etc/bashrc.d/ansible file to add /usr/local/bin to the PATHs of the relevant users. This is working AOK.

However, in my playbook I’m receiving the following error:

failed: [host2.example.com] (item=ansible.posix) => {"ansible_loop_var": "item", "changed": false, "item": "ansible.posix", "msg": "Failed to find required executable \"ansible-galaxy\" in paths: /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin"}

This means that my /etc/bashrc.d/ansible file (or any of the Ansible User’s various .bashrc, .bash_profile, etc, files) are not being picked up when performing the various tasks on the remote host.

BUT when I ssh into the remote host from the CLI the correct PATH is being correctly picked up.

So my questions are:

  • What is the best way to ensure that when working on the remote host the PATH is correctly set to include /usr/local/bin?
  • Is there some sort of Ansible Variable I should be setting?
  • Is there some sort of bashrc (or other file) that I need to (further) modify?
  • Is there some way of forcing the community.general.ansible_galaxy_install to include the “extra” PATH settings (I can’t find anything in the doco if it is there)?
  • Is there some other solution to my issue that I’ve overlooked? - which would not surprise me one bit; I’m still preety green in using Ansible.

Thanks in advance

Dulux-Oz

Yes, you can do this:

- name: Ansible collection install 
  community.general.ansible_galaxy_install:
    name: foo.bar
    type: collection
  environment:
    PATH: /usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Thank you @chris, that did the trick. :smile:

(Another factoid to add to my mostly-empty Ansible toolbox) :grin:

1 Like