From 63a1c1d43e17dd1d557281eb8e92a2f70c5be887 Mon Sep 17 00:00:00 2001 From: fumingwei Date: Mon, 20 Jan 2020 14:49:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=8E=E8=BF=9C=E7=A8=8B?= =?UTF-8?q?=E4=B8=BB=E6=9C=BAfact=E8=8E=B7=E5=8F=96=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=E6=9D=BF=E4=BF=A1=E6=81=AF=EF=BC=8C=E8=AE=A9=E4=B8=BB=E6=9C=BA?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=86=E7=BB=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy.yml | 4 ++++ roles/dogroups/files/dogroups.fact | 29 +++++++++++++++++++++++++++++ roles/dogroups/tasks/main.yml | 23 +++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 roles/dogroups/files/dogroups.fact create mode 100644 roles/dogroups/tasks/main.yml diff --git a/deploy.yml b/deploy.yml index fc424b3..d356d60 100644 --- a/deploy.yml +++ b/deploy.yml @@ -1,3 +1,7 @@ +- hosts: all + roles: + - dogroups + - hosts: Functional_Host roles: - framework diff --git a/roles/dogroups/files/dogroups.fact b/roles/dogroups/files/dogroups.fact new file mode 100644 index 0000000..f8a8cdd --- /dev/null +++ b/roles/dogroups/files/dogroups.fact @@ -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() diff --git a/roles/dogroups/tasks/main.yml b/roles/dogroups/tasks/main.yml new file mode 100644 index 0000000..d76969c --- /dev/null +++ b/roles/dogroups/tasks/main.yml @@ -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' } +