Run REX Job directly on Smart Proxy

We want to run a REX job directly on foreman/smart proxy. We need this to start ansible-playbook on the smart proxy in order to configure the application hosts. So, the ansible-playbook would run once for all hosts which are linked to the specific smart proxy.

Currently we do it like this:

This has a big drawback as it won’t work if the smart proxy host uses different organization / location because Host.find() only finds hosts of the currently selected organization / location. Means, the smart proxy host need to have exactly the same organization / location than the deployed application hosts.

I guess, there are other scenarios where it make sense to reference a smart proxy directly. What are your thoughts?

There is one workaround: instead of referencing the smart proxy directly, reference ONE host of the application. REX wiill determine the smart proxy on which the REX job should be started and everything should work. Drawback: in the REX job the ONE host is referenced.

Do you have an idea how to fix this somehow else?

I’m not sure I understand what you’re really after. There are two ways that could help addressing the issue.

  1. Technically - Host.unscoped.find_by(:name => proxy_name).id
  2. Semantically - see Infrastructure roles, we should able to detect hosts running proxies

This is exactly what I’m looking for for the long-term solution. Thank you very much.

I will try this one.