ERB code help

Hi All

I’m hoping this is the correct section (i can change to development if better) to post in. Basically I could really do with some help getting an ERB if statement to work. My template is to auto subscribe new hosts and I have it working by using gsub to remove parts of the foreman_url. See below. This works fine with the 4 proxies we have in difference DC’s, but for the master, it does not.

curl --insecure --output katello-ca-consumer-latest.noarch.rpm https://<%= foreman_url(‘provision’).gsub(/http://(.):./, ‘\1’) %>/pub/katello-ca-consumer-latest.noarch.rpm

When I preview this snippet against any host other than our master, it formats perfectly and works, but for the master, it fails and keeps http in there with the rest of the url:

https://http://sv-prod-foreman01.ourdomain.com/unattended/provision/pub/katello-ca-consumer-latest.noarch.rpm
Curl therefore fails.

I tried an if statement to simply curl the actual url (not the foreman_url variable but this is also failing:
<% if (foreman_url(‘provision’) == ‘http://sv-prod-foreman01.ourdomain.com’) -%>

curl --insecure --output /tmp/katello-ca-consumer-latest.noarch.rpm https://sv-prod-foreman01.ourdomain.com/pub/katello-ca-consumer-latest.noarch.rpm

<% else -%>
do something else

I’ve tried a few different formats for the foreman_url but no luck

Am I missing something very obvious?

Thanks,

You can use foreman_server_url instead which will return the value from the setting.

You can navigate to the Template DSL help via Administer > About on the right, the url is /templates_doc on your system. This gives you an overview of existing options and clicking on them will give you some explanation.

thank you
Would it need to be in the format: foreman_server_url(‘provision’) or just foreman_server_url ?

tried the following:

<% if foreman_server_url == ‘http://sv-prod-foreman-proxy01.mydomain.com’ -%>

curl --insecure --output katello-ca-consumer-latest.noarch.rpm https://sv-prod-foreman01.mydomain.com/pub/katello-ca-consumer-latest.noarch.rpm

rpm -Uvh katello-ca-consumer-latest.noarch.rpm

subscription-manager register --org=“mine” --activationkey=“NEW-EL8-LIBRARY”

yum install -y katello-host-tools katello-host-tools-tracer
katello-tracer-upload

<% else -%>

curl --insecure --output katello-ca-consumer-latest.noarch.rpm https://<%= foreman_url(‘provision’).gsub(/http://(.):./, ‘\1’) %>/pub/katello-ca-consumer-latest.noarch.rpm

rpm -Uvh katello-ca-consumer-latest.noarch.rpm

subscription-manager register --org=“mine” --activationkey=“my-EL8-LIBRARY”

yum install -y katello-host-tools katello-host-tools-tracer
katello-tracer-upload

<% end -%>

Same result:
running the preview against a host controlled by a proxy (else statement) formats and works fine
but against a host controlled by the master (sv-prod-foreman), it still shows the extra parts of the url even though Ive hardcoded the url (no gsub variables):

curl --insecure --output katello-ca-consumer-latest.noarch.rpm https://http://sv-prod-foreman01.mydomain.com/unattended/provision/pub/katello-ca-consumer-latest.noarch.rpm

think i have it, using:

<% if foreman_url(‘provision’) == ‘http://sv-prod-foreman01.mydomain.com/unattended/provision’ -%>

As a debugging tool, you can also use the ‘squid’ markers and it will output the values for you in the rendered template, for example <%= foreman_url('provision') %>.

spoke too soon. The preview tab finally worked using the above code against 2 different servers, which is what I needed
Then I built and the anaconda file showed it running differently to what the preview showed. Im stumped

thanks yes i did this and it’s definitely returning the correct value to what I expect to see and then use
I also checked the templates section in the legacyUI for this new host I built and it shows the correct code being used. anaconda shows the wrong command being used. Going to restart foreman now to see if something has cached but if anyone knows what else it could be, pls let me know