Skip to content
This repository has been archived by the owner on Jun 29, 2022. It is now read-only.

Commit

Permalink
convert cpu.* fact gathering to raw facts. Closes #107.
Browse files Browse the repository at this point in the history
  • Loading branch information
chambridge committed Jul 28, 2017
1 parent ebb464f commit 1d81f33
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
1 change: 0 additions & 1 deletion library/run_cmds.py
Expand Up @@ -52,7 +52,6 @@
# to the field requested using an '_').

DEFAULT_CMD_DICT = {"SysId": file_commands.SystemIdRhoCmd,
"Cpu": cpu_command.CpuRhoCmd,
"EtcRelease": etc_release_command.EtcReleaseRhoCmd,
"Virt": virt_command.VirtRhoCmd,
"RedhatPackages":
Expand Down
1 change: 1 addition & 0 deletions rho_playbook.yml
Expand Up @@ -14,6 +14,7 @@
- dmi
- subman
- redhat_release
- cpu


- name: write facts first to a variable and then to csv locally
Expand Down
85 changes: 85 additions & 0 deletions roles/cpu/tasks/main.yml
@@ -0,0 +1,85 @@
---

- name: gather cpu.vendor_id fact
raw: cat /proc/cpuinfo | grep '^vendor_id\s*:' | sed -n -e 's/^.*vendor_id\s*:\s//p'
register: cpu_vendor_id
ignore_errors: yes
when: '"Cpu_cpu.vendor_id" in facts_to_collect'

- name: add cpu.vendor_id to dictionary
set_fact:
cpu: "{{ cpu|default({}) | combine({ item: cpu_vendor_id['stdout_lines'][0] }) }}"
with_items:
- 'cpu.vendor_id'

- name: gather cpu.model_name fact
raw: cat /proc/cpuinfo | grep '^model name\s*:' | sed -n -e 's/^.*model name\s*:\s//p'
register: cpu_model_name
ignore_errors: yes
when: '"Cpu_cpu.model_name" in facts_to_collect'

- name: add cpu.model_name to dictionary
set_fact:
cpu: "{{ cpu|default({}) | combine({ item: cpu_model_name['stdout_lines'][0] }) }}"
with_items:
- 'cpu.model_name'

- name: gather cpu.bogomips fact
raw: cat /proc/cpuinfo | grep '^bogomips\s*:' | sed -n -e 's/^.*bogomips\s*:\s//p'
register: cpu_bogomips
ignore_errors: yes
when: '"Cpu_cpu.bogomips" in facts_to_collect'

- name: add cpu.bogomips to dictionary
set_fact:
cpu: "{{ cpu|default({}) | combine({ item: cpu_bogomips['stdout_lines'][0] }) }}"
with_items:
- 'cpu.bogomips'

- name: gather cpu.cpu_family fact
raw: cat /proc/cpuinfo | grep '^cpu family\s*:' | sed -n -e 's/^.*cpu family\s*:\s//p'
register: cpu_cpu_family
ignore_errors: yes
when: '"Cpu_cpu.cpu_family" in facts_to_collect'

- name: add cpu.cpu_family to dictionary
set_fact:
cpu: "{{ cpu|default({}) | combine({ item: cpu_cpu_family['stdout_lines'][0] }) }}"
with_items:
- 'cpu.cpu_family'

- name: gather cpu.model_ver fact
raw: cat /proc/cpuinfo | grep '^model\s*:' | sed -n -e 's/^.*model\s*:\s//p'
register: cpu_model_ver
ignore_errors: yes
when: '"Cpu_cpu.model_ver" in facts_to_collect'

- name: add cpu.model_ver to dictionary
set_fact:
cpu: "{{ cpu|default({}) | combine({ item: cpu_model_ver['stdout_lines'][0] }) }}"
with_items:
- 'cpu.model_ver'

- name: gather cpu.count fact
raw: cat /proc/cpuinfo | grep '^processor\s*:' | wc -l
register: cpu_count
ignore_errors: yes
when: '"Cpu_cpu.count" in facts_to_collect'

- name: add cpu.count to dictionary
set_fact:
cpu: "{{ cpu|default({}) | combine({ item: cpu_count['stdout_lines'][0] }) }}"
with_items:
- 'cpu.count'

- name: gather cpu.socket_count fact
raw: sudo -n /usr/sbin/dmidecode -t 4 | grep 'Socket Designation'| wc -l
register: cpu_socket_count
ignore_errors: yes
when: '"Cpu_cpu.socket_count" in facts_to_collect'

- name: add cpu.socket_count to dictionary
set_fact:
cpu: "{{ cpu|default({}) | combine({ item: cpu_socket_count['stdout_lines'][0] }) }}"
with_items:
- 'cpu.socket_count'
2 changes: 1 addition & 1 deletion roles/write/tasks/main.yml
@@ -1,7 +1,7 @@
---

- name: store facts from all hosts in a variable
set_fact: host_fact={{hostvars[item]["res"] | combine(hostvars[item]["uname"]) | combine(hostvars[item]["date"]) | combine(hostvars[item]["file_contents"]) | combine(hostvars[item]["dmi"]) | combine(hostvars[item]["subman"]) | combine(hostvars[item]["redhat_release"]) }}
set_fact: host_fact={{hostvars[item]["res"] | combine(hostvars[item]["uname"]) | combine(hostvars[item]["date"]) | combine(hostvars[item]["file_contents"]) | combine(hostvars[item]["dmi"]) | combine(hostvars[item]["subman"]) | combine(hostvars[item]["redhat_release"]) | combine(hostvars[item]["cpu"]) }}
with_items: "{{groups.alpha}}"
register: host_facts

Expand Down

0 comments on commit 1d81f33

Please sign in to comment.