增加从远程主机fact获取计算板信息,让主机自动分组功能
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
|
- hosts: all
|
||||||
|
roles:
|
||||||
|
- dogroups
|
||||||
|
|
||||||
- hosts: Functional_Host
|
- hosts: Functional_Host
|
||||||
roles:
|
roles:
|
||||||
- framework
|
- framework
|
||||||
|
|||||||
29
roles/dogroups/files/dogroups.fact
Normal file
29
roles/dogroups/files/dogroups.fact
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
|
def get_IPMB_location():
|
||||||
|
cmdtodo = 'ipmitool raw 0x2e 0x32 0x13 0x5f 0x00'
|
||||||
|
numStr = None
|
||||||
|
optdl = os.popen(cmdtodo)
|
||||||
|
strlocation = optdl.read()
|
||||||
|
if not len(strlocation):
|
||||||
|
optdl.close()
|
||||||
|
return None
|
||||||
|
optdl.close()
|
||||||
|
infos = re.split(' |\n',strlocation)
|
||||||
|
if infos[5] == '90':
|
||||||
|
numStr = 'zero'
|
||||||
|
if infos[5] == '80':
|
||||||
|
numStr = 'one'
|
||||||
|
if infos[5] == '88':
|
||||||
|
numStr = 'two'
|
||||||
|
if infos[5] == '98':
|
||||||
|
numStr = 'three'
|
||||||
|
if numStr == -1:
|
||||||
|
return None
|
||||||
|
return json.dumps(numStr)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print get_IPMB_location()
|
||||||
23
roles/dogroups/tasks/main.yml
Normal file
23
roles/dogroups/tasks/main.yml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
|
||||||
|
- name: 'copy dogroups.fact to host'
|
||||||
|
copy:
|
||||||
|
src: "{{ role_path }}/files/dogroups.fact"
|
||||||
|
dest: "/etc/ansible/facts.d/dogroups.fact"
|
||||||
|
mode: "0755"
|
||||||
|
|
||||||
|
- name: 'Gathers facts from remote hosts'
|
||||||
|
setup:
|
||||||
|
filter: 'ansible_local'
|
||||||
|
fact_path: /etc/ansible/facts.d
|
||||||
|
|
||||||
|
- name: 'group by gathers facts'
|
||||||
|
group_by:
|
||||||
|
key: '{{item.key}}'
|
||||||
|
when: ansible_local.dogroups == item.value
|
||||||
|
with_items:
|
||||||
|
- { key: 'blade-00', value: 'zero' }
|
||||||
|
- { key: 'blade-01', value: 'one' }
|
||||||
|
- { key: 'blade-02', value: 'two' }
|
||||||
|
- { key: 'blade-03', value: 'three' }
|
||||||
|
|
||||||
Reference in New Issue
Block a user