Maybe this will help you: is definitely possibile to use the varaibles
defined in Foreman in an Ansible Playbook: by definig some parameters in
Foreman on the host, and then executing a role with something like: *-
debug: msg="Here all the host variables {{ hostvars }}" *all the host's
variables are shown.
Organizing them with a JSON formatter like
*https://jsonformatter.curiousconcept.com/* and then searching for the
variable name, it can be see that all the host parameters are inside
foreman_params.
Therefore, they can be accessed inside a playbook with something like *{{
foreman_params['my_parameter'] }}* .
With that, I have created some roles to try to extend the functionalities
of the Ansible Plugin. Using parameters and by writing roles that use those
parameters, I can write a list of tasks to execute on a host, launch a
single playbook on an host, using options like --syntax-check; I can also
import the roles inside a git repository specifying the user's credentials,
import a given role from ansible-galaxy.
The sky is the limit with the freedom of user-defined parameters!
So far, my host has 10 variables, with pretty random names, that has been
used successfully in the roles I've created (they don't have to start with
"ansible_" to be used in a playbook): the only thing is that you have to
launch the role from the plugin inside Foreman, using Anbile from the
command line in the host doesn't work.
An other thing: is that if the parameter has some of the YAML special
chars, to make it work you can wrap the entire value with something like *{%
raw %}* *var_value* *{% endraw %}*: otherwise it can't be used and there
will be issues even with roles that use other parameters.
I'm sorry if this post is inappropriate: if you need, feel free to remove
it.
I'm finishing a 2-months internship that had the objective to integrate
Ansible with Foreman and Katello using the roles, so this was part of the
work I've done.
Thank you for your work, I look forward to see the next Foreman Community
Demo.
Best
Pietro Gabelli
On Monday, July 17, 2017 at 2:54:30 PM UTC+2, Daniel Lobato wrote:
>
> On 07/14, [email protected] <javascript:> wrote:
> > Hi,
> >
> > first of all, I'd like to thank you for the great work you've done so
> far.
> > I really admire all of you guys.
> > My programming skills are not so good so I'll only lend my hand in
> > proposing an idea or two that might be useful.
> >
> > Before I run Ansible role directly I can specify certain connection
> > parameters in an Ansible inventory file.
> > As you know the same option is available in the Foreman GUI interface
> via
> > parameters (Global parameters, Host group parameters etc.).
> > However, there is one limitation and that is the list of parameters
> > administrators can specify is limited. To get an idea which parameters
> are
> > available
> > one can take a look in the following ruby scripts
> >
> >
> /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_ansible-1.4.5/app/services/foreman_ansible/inventory_creator.rb
>
>
> > and
> >
> /opt/theforeman/tfm/root/usr/share/gems/gems/foreman_ansible-1.4.5/app/models/setting/ansible.rb
>
>
> > .
> >
> > The problem arise when somebody needs a parameter that is not listed
> there.
> > Okay, you can edit both above mentioned scripts and then restart
> Foreman,
> > but every time the official update is applied, you have to add all
> > necessary code changes again. This sucks and I believe everyone agrees
> with
> > me.
> >
> > So the idea I'd suggest is that, let administrators define what
> parameter
> > they need/want without hard-coding into Foreman Ansible plugin ruby
> > scripts, OR
> > make them hard-coded but the list of available parameter must be
> complete.
> >
> > What do you think?
>
> I think it makes a lot of sense and at this point it's an easier thing
> to implement than having to add a new parameter every time someone
> requests it (or Ansible releases something new). I would expect
> something like that for Foreman-Ansible 1.5 or 1.6
>
> >
> >
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups "foreman-dev" group.
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected] <javascript:>.
> > For more options, visit https://groups.google.com/d/optout.
>
>
> --
> Daniel Lobato Garcia
>
> @dLobatog
> blog.daniellobato.me
> daniellobato.me
>
> GPG: http://keys.gnupg.net/pks/lookup?op=get&search=0x7A92D6DD38D6DE30
> Keybase: https://keybase.io/elobato
>
--
You received this message because you are subscribed to the Google Groups
"foreman-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.