Remote exaction - trying to create a template that perform user a according user selection

Hi,
I am trying to create template with base on user input
answer user have yes or no
The second thing is I create input with hostname so I would like to run on the hostname that user mention. ( hostname I didn’t know where the put it :\ )
example-
<% if <%= input(‘answer’) -%> == ‘yes’ %>
<%= render_template(‘Ansible Join to domain - commands - SDL’) %>
echo “done - join the domain”
<% else %>
echo “done - didnt join to the domain”
<% end %>

Thanks in advance,
shay

I tiered also vi ansible

  • name: remote command on a single host add to domain
    job_invocation:
    search_query: “name ^ <%= input(‘hostnamea’) -%>”
    job_template: “Ansible Join to domain - commands - SDL”
    when: <%= input(‘domain’) -%> == “yes”
    didn’t recognize job_invocation

If I understand the usecase correctly, you are building a job (so creating a Job Template), that will be executed on host, e.g. target.example.com to join some domain. The resulting script should be executed on the target machine. The target is typically not specified as an input. Instead, you run the job on a given host. That means the host target.example.com must be registered to your Foreman first. Given the job is then executed on the host, Foreman opens SSH connection to it, therefore Foreman’s SSH key must be installed on the target.example.com

Once you have the Job Template ready, navigate the Host detail page on which you want to execute that. There’s a “Schedule a job” drop down, click on that and select the job you want to run.

There are other ways how you can run the job, e.g. on multiple hosts at a same time. But the point is, the target machine is not a job input.

I may have misunderstood the goal completely, so please try to explain what your’e after if that’s the case.

Hi,
This is a part of larger template that adding servers to the foreman.
I created a pipeline via ansible that connection servers to foreman and performing all kinds of other processes. ( it works, ssh key was imported on pre installation by kickstart)
I want to add to the last section to ask if I would like to add the server to domain.
most of the servers are need to join to the domain, I have anther template who do it.
Instead of running two separate pipelines why not run one pipeline that does everything

I would appreciate it if you could help me to write it correctly :slight_smile:

Oh, so are you trying to pass hostname from one template to another?

I guess something like this

<%= render_template('Ansible Join to domain - commands - SDL’, hostname: @host.name) %>

the @host.name refers to the name of the host this job is rendered for. The hostname: is the input name of the Ansible Join to domain - commands - SDL template. I hope I got it correctly this time :slight_smile:

Hi,
hostnamea refers to the user that write manually the hostname and the answer is to join domain or not. ( I configure both of them at template inputs)

I tried this script but I got error on the syntax

<%= if <%= input('answer") -%> == “yes” -%>
<%= render_template(‘Ansible Join to domain - commands - SDL’, hostname: <%= input(‘hostnamea’) -%>) -%>
echo “done - join the domain”
<% else %>
echo “done - didnt join to the domain”
<% end %>
[/quote]

You are getting syntax errors because you are stacking erb template snippets into each other.
Instead of doing <%= if <%= input('answer") -%> == “yes” -%> you can just do <%= if input('answer') == “yes” -%>, similar for the render_tempalte line.
The erb syntax with different variations of <% code %> tells the interpreter that code is to be interpreted as ruby, so it tries to interpret things like <%= in your template as ruby code, which it is not.

Hope this helps :slight_smile:
Regards

Didn’t work :\ maybe to run it via ansible playbook
<%= if input(‘domain’) == “yes” -%>
<%= render_template(‘Ansible Join to domain - commands - SDL’, hostname: input(‘hostnamea’)) -%>
<%= end -%>