我的要求是我能夠從主機獲取主機名和Java版本,將這些值存入本地主機並將其存儲在數據庫中。 我能夠獲取本地主機上的Java版本,最後一步是存儲在數據庫中的這些變量的值..任何人都可以建議我怎麼能繼續與Ansible:需要有關與數據庫(Oracle/MySql)連接的信息
---
- 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']