On 03. mars 2017 19:51, Gilberto Valentin wrote:
Hello, I am interested in pulling specific data from a table/field and
apply that data to a .j2 template. For example, if I have a license key in
a table on a field called RedHat license, I want to pull that license value
and have my .j2 template use it for the creation of an XML template. I was
pointed to the lookup plugin (
https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/lookup)
but there isn't anything there for MySQL. There is one for MongoDB, though.
The issue is that I don't know how I would use these plugins and I don't
know how to write plugins yet or how I would include one for the lookup
plugin. What would be the best approach in my case? If I need to write my
own plugin, is there a document that can guide me on this and how I would
incorporate it with lookup? Thanks

You could use the command module and run an mysql query.

- name: Run a playbook
command: mysql -u <user> -p<passwd> --silent --skip-column-names --execute="SELECT <column> FROM <table>"
  register: result

Then you can use the variable result.stdout and/or result.stdout_lines to get the result.

(I don't recommend using -p<passwd>, use a option file instead, but easier to show a -p on the command line)

--
Kai Stian Olstad

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/843aa1f3-d96d-4f66-04cd-90a3e20465ce%40olstad.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to