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

Commit

Permalink
patch for variable reuse.
Browse files Browse the repository at this point in the history
  • Loading branch information
chambridge committed Oct 19, 2017
1 parent 221183b commit 1151af3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 70 deletions.
8 changes: 4 additions & 4 deletions roles/cpu/tasks/main.yml
Expand Up @@ -84,20 +84,20 @@

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

- name: extract result value for cpu.socket_count
set_fact:
cpu_socket_count: "{{ cpu_socket_count['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"cpu.socket_count" in facts_to_collect and "stdout" in cpu_socket_count'
cpu_socket_count: "{{ cpu_socket_count_cmd['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"cpu.socket_count" in facts_to_collect and "stdout" in cpu_socket_count_cmd'

- name: handle failure value for cpu.socket_count
set_fact:
cpu_socket_count: "{{ 'error' if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"cpu.socket_count" in facts_to_collect and "stdout" not in cpu_socket_count'
when: '"cpu.socket_count" in facts_to_collect and "stdout" not in cpu_socket_count_cmd'

- name: add cpu.socket_count to dictionary
set_fact:
Expand Down
8 changes: 4 additions & 4 deletions roles/date/tasks/main.yml
Expand Up @@ -69,20 +69,20 @@

- name: gather date.yum_history fact
raw: yum history | tail -n 4 | grep -o '[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}'
register: date_yum_history
register: date_yum_history_cmd
become: yes
ignore_errors: yes
when: 'have_yum and "date.yum_history" in facts_to_collect'

- name: extract result value for date.yum_history
set_fact:
date_yum_history: "{{ date_yum_history['stdout_lines'] | select | first | default('error') if have_yum else 'N/A (yum not found)' }}"
when: '"date.yum_history" in facts_to_collect and "stdout_lines" in date_yum_history'
date_yum_history: "{{ date_yum_history_cmd['stdout_lines'] | select | first | default('error') if have_yum else 'N/A (yum not found)' }}"
when: '"date.yum_history" in facts_to_collect and "stdout_lines" in date_yum_history_cmd'

- name: handle failure value for date.yum_history
set_fact:
date_yum_history: "{{ 'error' if have_yum else 'N/A (yum not found)' }}"
when: '"date.yum_history" in facts_to_collect and "stdout_lines" not in date_yum_history'
when: '"date.yum_history" in facts_to_collect and "stdout_lines" not in date_yum_history_cmd'

- name: add date.yum_history to dictionary
set_fact:
Expand Down
32 changes: 16 additions & 16 deletions roles/dmi/tasks/main.yml
Expand Up @@ -6,20 +6,20 @@

- name: gather dmi.bios-vendor fact
raw: /usr/sbin/dmidecode -s bios-vendor
register: dmi_bios_vendor
register: dmi_bios_vendor_cmd
ignore_errors: yes
become: yes
when: '"dmi.bios-vendor" in facts_to_collect'

- name: extract result value for dmi.bios-vendor
set_fact:
dmi_bios_vendor: "{{ dmi_bios_vendor['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.bios-vendor" in facts_to_collect and "stdout" in dmi_bios_vendor'
dmi_bios_vendor: "{{ dmi_bios_vendor_cmd['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.bios-vendor" in facts_to_collect and "stdout" in dmi_bios_vendor_cmd'

- name: handle failure value for dmi.bios-vendor
set_fact:
dmi_bios_vendor: "{{ 'error' if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.bios-vendor" in facts_to_collect and "stdout" not in dmi_bios_vendor'
when: '"dmi.bios-vendor" in facts_to_collect and "stdout" not in dmi_bios_vendor_cmd'

- name: add dmi.bios-vendor to dictionary
set_fact:
Expand All @@ -30,20 +30,20 @@

- name: gather dmi.bios-version fact
raw: /usr/sbin/dmidecode -s bios-version
register: dmi_bios_version
register: dmi_bios_version_cmd
ignore_errors: yes
become: yes
when: '"dmi.bios-version" in facts_to_collect'

- name: extract result value for dmi.bios-version
set_fact:
dmi_bios_version: "{{ dmi_bios_vendor['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.bios-version" in facts_to_collect and "stdout" in dmi_bios_version'
dmi_bios_version: "{{ dmi_bios_version_cmd['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.bios-version" in facts_to_collect and "stdout" in dmi_bios_version_cmd'

- name: handle failure value for dmi.bios-version
set_fact:
dmi_bios_version: "{{ 'error' if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.bios-version" in facts_to_collect and "stdout" not in dmi_bios_version'
when: '"dmi.bios-version" in facts_to_collect and "stdout" not in dmi_bios_version_cmd'

- name: add dmi.bios-version to dictionary
set_fact:
Expand All @@ -54,20 +54,20 @@

- name: gather dmi.system-manufacturer fact
raw: /usr/sbin/dmidecode | grep -A4 'System Information' | grep 'Manufacturer' | sed -n -e 's/^.*Manufacturer:\s//p'
register: dmi_system_manufacturer
register: dmi_system_manufacturer_cmd
ignore_errors: yes
become: yes
when: '"dmi.system-manufacturer" in facts_to_collect'

- name: extract result value for dmi.system-manufacturer
set_fact:
dmi_system_manufacturer: "{{ dmi_system_manufacturer['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.system-manufacturer" in facts_to_collect and "stdout" in dmi_system_manufacturer'
dmi_system_manufacturer: "{{ dmi_system_manufacturer_cmd['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.system-manufacturer" in facts_to_collect and "stdout" in dmi_system_manufacturer_cmd'

- name: handle failure value for dmi.system-manufacturer
set_fact:
dmi_system_manufacturer: "{{ 'error' if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.system-manufacturer" in facts_to_collect and "stdout" not in dmi_system_manufacturer'
when: '"dmi.system-manufacturer" in facts_to_collect and "stdout" not in dmi_system_manufacturer_cmd'

- name: add dmi.system-manufacturer to dictionary
set_fact:
Expand All @@ -78,20 +78,20 @@

- name: gather dmi.processor-family fact
raw: /usr/sbin/dmidecode -s processor-family
register: dmi_processor_family
register: dmi_processor_family_cmd
ignore_errors: yes
become: yes
when: '"dmi.processor-family" in facts_to_collect'

- name: extract result value for dmi.processor-family
set_fact:
dmi_processor_family: "{{ dmi_processor_family['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.processor-family" in facts_to_collect and "stdout" in dmi_processor_family'
dmi_processor_family: "{{ dmi_processor_family_cmd['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.processor-family" in facts_to_collect and "stdout" in dmi_processor_family_cmd'

- name: handle failure value for dmi.processor-family
set_fact:
dmi_processor_family: "{{ 'error' if have_dmidecode else 'N/A (dmidecode not found)' }}"
when: '"dmi.processor-family" in facts_to_collect and "stdout" not in dmi_processor_family'
when: '"dmi.processor-family" in facts_to_collect and "stdout" not in dmi_processor_family_cmd'

- name: add dmi.processor-family to dictionary
set_fact:
Expand Down
48 changes: 24 additions & 24 deletions roles/subman/tasks/main.yml
Expand Up @@ -6,20 +6,20 @@

- name: gather subman.cpu.cpu(s) fact
raw: subscription-manager facts --list | grep '^cpu.cpu(s).' | sed -n -e 's/^.*cpu.cpu(s).\s*//p'
register: subman_cpu_cpu
register: subman_cpu_cpu_cmd
ignore_errors: yes
become: yes
when: 'have_subscription_manager and "subman.cpu.cpu(s)" in facts_to_collect'

- name: extract result value for subman.cpu.cpu(s)
set_fact:
subman_cpu_cpu: "{{ subman_cpu_cpu['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.cpu(s)" in facts_to_collect and "stdout" in subman_cpu_cpu'
subman_cpu_cpu: "{{ subman_cpu_cpu_cmd['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.cpu(s)" in facts_to_collect and "stdout" in subman_cpu_cpu_cmd'

- name: handle failure value for subman.cpu.cpu(s)
set_fact:
subman_cpu_cpu: "{{ 'error' if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.cpu(s)" in facts_to_collect and "stdout" not in subman_cpu_cpu'
when: '"subman.cpu.cpu(s)" in facts_to_collect and "stdout" not in subman_cpu_cpu_cmd'

- name: add subman.cpu.cpu(s) to dictionary
set_fact:
Expand All @@ -30,20 +30,20 @@

- name: gather subman.cpu.core(s)_per_socket fact
raw: subscription-manager facts --list | grep '^cpu.core(s)_per_socket.' | sed -n -e 's/^.*cpu.core(s)_per_socket.\s*//p'
register: subman_cpu_core_per_socket
register: subman_cpu_core_per_socket_cmd
ignore_errors: yes
become: yes
when: 'have_subscription_manager and "subman.cpu.core(s)_per_socket" in facts_to_collect'

- name: extract result value for subman.cpu.core(s)_per_socket
set_fact:
subman_cpu_core_per_socket: "{{ subman_cpu_core_per_socket['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.core(s)_per_socket" in facts_to_collect and "stdout" in subman_cpu_core_per_socket'
subman_cpu_core_per_socket: "{{ subman_cpu_core_per_socket_cmd['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.core(s)_per_socket" in facts_to_collect and "stdout" in subman_cpu_core_per_socket_cmd'

- name: handle failure value for subman.cpu.core(s)_per_socket
set_fact:
subman_cpu_core_per_socket: "{{ 'error' if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.core(s)_per_socket" in facts_to_collect and "stdout" not in subman_cpu_core_per_socket'
when: '"subman.cpu.core(s)_per_socket" in facts_to_collect and "stdout" not in subman_cpu_core_per_socket_cmd'

- name: add subman.cpu.core(s)_per_socket to dictionary
set_fact:
Expand All @@ -54,20 +54,20 @@

- name: gather subman.cpu.cpu_socket(s) fact
raw: subscription-manager facts --list | grep '^cpu.cpu_socket(s).' | sed -n -e 's/^.*cpu.cpu_socket(s).\s*//p'
register: subman_cpu_cpu_socket
register: subman_cpu_cpu_socket_cmd
ignore_errors: yes
become: yes
when: 'have_subscription_manager and "subman.cpu.cpu_socket(s)" in facts_to_collect'

- name: extract result value for subman.cpu.cpu_socket(s)
set_fact:
subman_cpu_cpu_socket: "{{ subman_cpu_core_per_socket['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.cpu_socket(s)" in facts_to_collect and "stdout" in subman_cpu_cpu_socket'
subman_cpu_cpu_socket: "{{ subman_cpu_cpu_socket_cmd['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.cpu_socket(s)" in facts_to_collect and "stdout" in subman_cpu_cpu_socket_cmd'

- name: handle failure value for subman.cpu.cpu_socket(s)
set_fact:
subman_cpu_cpu_socket: "{{ 'error' if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.cpu.cpu_socket(s)" in facts_to_collect and "stdout" not in subman_cpu_cpu_socket'
when: '"subman.cpu.cpu_socket(s)" in facts_to_collect and "stdout" not in subman_cpu_cpu_socket_cmd'

- name: add subman.cpu.cpu_socket(s) to dictionary
set_fact:
Expand All @@ -78,20 +78,20 @@

- name: gather subman.virt.host_type fact
raw: subscription-manager facts --list | grep '^virt.host_type.' | sed -n -e 's/^.*virt.host_type.\s*//p'
register: subman_virt_host_type
register: subman_virt_host_type_cmd
ignore_errors: yes
become: yes
when: 'have_subscription_manager and "subman.virt.host_type" in facts_to_collect'

- name: extract result value for subman.virt.host_type
set_fact:
subman_virt_host_type: "{{ subman_virt_host_type['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.host_type" in facts_to_collect and "stdout" in subman_virt_host_type'
subman_virt_host_type: "{{ subman_virt_host_type_cmd['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.host_type" in facts_to_collect and "stdout" in subman_virt_host_type_cmd'

- name: handle failure value for subman.virt.host_type
set_fact:
subman_virt_host_type: "{{ 'error' if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.host_type" in facts_to_collect and "stdout" not in subman_virt_host_type'
when: '"subman.virt.host_type" in facts_to_collect and "stdout" not in subman_virt_host_type_cmd'

- name: add subman.virt.host_type to dictionary
set_fact:
Expand All @@ -102,20 +102,20 @@

- name: gather subman.virt.is_guest fact
raw: subscription-manager facts --list | grep '^virt.is_guest.' | sed -n -e 's/^.*virt.is_guest.\s*//p'
register: subman_virt_is_guest
register: subman_virt_is_guest_cmd
ignore_errors: yes
become: yes
when: 'have_subscription_manager and "subman.virt.is_guest" in facts_to_collect'

- name: extract result value for subman.virt.is_guest
set_fact:
subman_virt_is_guest: "{{ subman_virt_is_guest['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.is_guest" in facts_to_collect and "stdout" in subman_virt_is_guest'
subman_virt_is_guest: "{{ subman_virt_is_guest_cmd['stdout'] | string() | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.is_guest" in facts_to_collect and "stdout" in subman_virt_is_guest_cmd'

- name: handle failure value for subman.virt.is_guest
set_fact:
subman_virt_is_guest: "{{ 'error' if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.is_guest" in facts_to_collect and "stdout" not in subman_virt_is_guest'
when: '"subman.virt.is_guest" in facts_to_collect and subman_virt_is_guest_cmd is mapping and "stdout" not in subman_virt_is_guest_cmd'

- name: add subman.virt.is_guest to dictionary
set_fact:
Expand All @@ -126,20 +126,20 @@

- name: gather subman.virt.uuid fact
raw: subscription-manager facts --list | grep '^virt.uuid.' | sed -n -e 's/^.*virt.uuid.\s*//p'
register: subman_virt_uuid
register: subman_virt_uuid_cmd
ignore_errors: yes
become: yes
when: 'have_subscription_manager and "subman.virt.uuid" in facts_to_collect'

- name: extract result value for subman.virt.uuid
set_fact:
subman_virt_uuid: "{{ subman_virt_uuid['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.uuid" in facts_to_collect and "stdout" in subman_virt_uuid'
subman_virt_uuid: "{{ subman_virt_uuid_cmd['stdout'] | trim | default('error') if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.uuid" in facts_to_collect and "stdout" in subman_virt_uuid_cmd'

- name: handle failure value for subman.virt.is_guest
set_fact:
subman_virt_uuid: "{{ 'error' if have_subscription_manager else 'N/A (subscription-manager not found)' }}"
when: '"subman.virt.uuid" in facts_to_collect and "stdout" not in subman_virt_uuid'
when: '"subman.virt.uuid" in facts_to_collect and "stdout" not in subman_virt_uuid_cmd'

- name: add subman.virt.uuid to dictionary
set_fact:
Expand Down

0 comments on commit 1151af3

Please sign in to comment.