Provisioning template condition is not validated (@host.architecture)

Hi,

I have following Finish template defined:

<% if @host.architecture == "x86_64" -%>
echo "Converting <%= @host.shortname %> from DHCP to static IP address…"
JSROOT="/a"
MYIF=ls ${JSROOT}/etc/dhcp.*0 | awk -F. &#39;{ print $2 }&#39;
rm -f ${B}/etc/dhcp.*
echo -e "<%= @host.shortname %>" > ${JSROOT}/etc/hostname.$MYIF
echo -e "<%= @host.shortname %>" > ${JSROOT}/etc/nodename
echo -e "<%= @host.ip %>\t<%= @host.shortname %> loghost" >>
${JSROOT}/etc/inet/hosts
echo -e "<%= @host.ip %>\t<%= @host.shortname %> loghost" >>
${JSROOT}/etc/inet/ipnodes
<% end -%>

Architecture is: <%= @host.architecture %>

When I am trying on x86_64 host, I don't get this IF validated, despite
that it returns:

Architecture is: x86_64

If I change <% if @host.architecture != "x86_64" -%> it validates it
properly. The host architecture x86_64 and I followed the template guide
http://projects.theforeman.org/projects/1/wiki/TemplateWriting

It looks like something is broken, as I can't find what is wrong with my
template.

Regards,
AF

> Hi,
>
> I have following Finish template defined:
>
> <% if @host.architecture == "x86_64" -%>
> echo "Converting <%= @host.shortname %> from DHCP to static IP address…"
> JSROOT="/a"
> MYIF=ls ${JSROOT}/etc/dhcp.*0 | awk -F. &#39;{ print $2 }&#39;
> rm -f ${B}/etc/dhcp.*
> echo -e "<%= @host.shortname %>" > ${JSROOT}/etc/hostname.$MYIF
> echo -e "<%= @host.shortname %>" > ${JSROOT}/etc/nodename
> echo -e "<%= @host.ip %>\t<%= @host.shortname %> loghost" >>
> ${JSROOT}/etc/inet/hosts
> echo -e "<%= @host.ip %>\t<%= @host.shortname %> loghost" >>
> ${JSROOT}/etc/inet/ipnodes
> <% end -%>
>
> Architecture is: <%= @host.architecture %>
>
>
> When I am trying on x86_64 host, I don't get this IF validated, despite
> that it returns:
>
> Architecture is: x86_64
>
> If I change <% if @host.architecture != "x86_64" -%> it validates it
> properly. The host architecture x86_64 and I followed the template guide
> TemplateWriting - Foreman
>
> It looks like something is broken, as I can't find what is wrong with my
> template.
>
actually, when you do <%= %> it automatically converts the object into a
string,
when you could do instead is
<% if @host.architecture.to_s == "x86_64" -%>
or
<% if @host.architecture.name == "x86_64" -%>

there are more methods/functions that architecture respond to, for example,
architecture.created_at, updated_at, operatingsystems etc etc…

Ohad

··· On Mon, Dec 2, 2013 at 6:30 AM, Aleksei Feltin wrote:

Regards,
AF


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks Ohad,

I got it working now.

Regards,
AF

··· On Monday, December 2, 2013 6:07:11 PM UTC+11, ohad wrote: > > > > > On Mon, Dec 2, 2013 at 6:30 AM, Aleksei Feltin <aleksei...@gmail.com > > wrote: > >> Hi, >> >> I have following Finish template defined: >> >> <% if @host.architecture == "x86_64" -%> >> echo "Converting <%= @host.shortname %> from DHCP to static IP address..." >> JSROOT="/a" >> MYIF=`ls ${JSROOT}/etc/dhcp.*0 | awk -F. '{ print $2 }'` >> rm -f ${B}/etc/dhcp.* >> echo -e "<%= @host.shortname %>" > ${JSROOT}/etc/hostname.$MYIF >> echo -e "<%= @host.shortname %>" > ${JSROOT}/etc/nodename >> echo -e "<%= @host.ip %>\t<%= @host.shortname %> loghost" >> >> ${JSROOT}/etc/inet/hosts >> echo -e "<%= @host.ip %>\t<%= @host.shortname %> loghost" >> >> ${JSROOT}/etc/inet/ipnodes >> <% end -%> >> >> Architecture is: <%= @host.architecture %> >> >> >> When I am trying on x86_64 host, I don't get this IF validated, despite >> that it returns: >> >> *Architecture is: x86_64* >> >> If I change <% if @host.architecture != "x86_64" -%> it validates it >> properly. The host architecture x86_64 and I followed the template guide >> http://projects.theforeman.org/projects/1/wiki/TemplateWriting >> >> It looks like something is broken, as I can't find what is wrong with my >> template. >> > actually, when you do <%= %> it automatically converts the object into a > string, > when you could do instead is > <% if @host.architecture.to_s == "x86_64" -%> > or > <% if @host.architecture.name == "x86_64" -%> > > there are more methods/functions that architecture respond to, for > example, architecture.created_at, updated_at, operatingsystems etc etc.. > > Ohad > > > >> Regards, >> AF >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Foreman users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to foreman-user...@googlegroups.com . >> To post to this group, send email to forema...@googlegroups.com >> . >> Visit this group at http://groups.google.com/group/foreman-users. >> For more options, visit https://groups.google.com/groups/opt_out. >> > >