Ansible : Need information regarding the connection with Database (Oracle/MySql)

20 views
Skip to first unread message

nishant bawane

unread,
Apr 10, 2017, 2:34:11 PM4/10/17
to Ansible Project
Below is the task.. I need to connect to host server.. fetch the host name nad current java version and store it in the database on local server. I am able to fetch the host name and java version.. but need assistance reading the sotring the value of variable in DATABASE. Can anyone please suggest how to proceed with that -

---
- hosts: myserver
  tasks:

  - name: Get the Host Name
    shell: host $(hostname -i) | awk '{print $NF }'|sed 's/\.$//'
    register: hosts
  - set_fact: the_hosts=hosts.stdout
  - debug: var={{the_hosts}}

  - name: Fetch Java Version
    shell: /opt/app/java/jdk/jdk180_66/64bit/bin/java -version 2>&1 | grep version | awk '{print $3}' | sed 's/"//g'
    register: result
  - set_fact: the_count=result.stdout
  - debug: var={{the_count}}

- hosts: localhost
  tasks:

  - debug: var=hostvars['zlp12036']['result']['stdout']
  - debug: var=hostvars['zlp12037']['result']['stdout']
  - debug: var=hostvars['zlp12036']['hosts']['stdout']
  - debug: var=hostvars['zlp12037']['hosts']['stdout']
----------------------------------------------------------------------------------------------------------------------------------------------------------


I am able to get the values under the debug.

Second step is to store the same inside the Database on my local server.
Need information for the same.

J Hawkesworth

unread,
Apr 10, 2017, 5:44:41 PM4/10/17
to Ansible Project
I think you just need to find or write a module to store the results using some sql. I found a reference to some oracle modules here https://liquidat.wordpress.com/2017/02/17/ansible-community-modules-for-oracle-db-asm/ including a couple of modules for this interacting with database.

If you go with oracle, consider using Merge On syntax which would give you a sort of idempotent behavior. Mysql likely has something similar too, although I don't know what the syntax might be.

Hope thus helps,

Jon

Reply all
Reply to author
Forward
0 new messages