Skip to content

Commit

Permalink
Make tasks return the empty string for errors
Browse files Browse the repository at this point in the history
This is how we are modeling errors in Sonar, so we need to convert all
of the tasks to match.
  • Loading branch information
Noah Lavine committed Feb 7, 2018
1 parent c593560 commit 36efb90
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 31 deletions.
10 changes: 5 additions & 5 deletions roles/cpu/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

- name: extract result value for cpu.socket_count
set_fact:
cpu_socket_count: "{{ internal_cpu_socket_count_cmd.get('stdout') | trim | default('error') if internal_have_dmidecode else 'N/A (dmidecode not found)' }}"
cpu_socket_count: "{{ internal_cpu_socket_count_cmd.get('stdout') | trim | default('') if internal_have_dmidecode else '' }}"
when: '"stdout" in internal_cpu_socket_count_cmd'

- name: gather cpu.socket_count fact with fallback
Expand All @@ -91,19 +91,19 @@
- name: calculate cpu.core_count
set_fact:
cpu_core_count: "{{ (cpu_core_per_socket | int) * (cpu_socket_count | int)}}"
when: 'cpu_core_per_socket is defined and cpu_core_per_socket != "Not Found"'
when: 'cpu_core_per_socket is defined and cpu_core_per_socket'

- name: calculate cpu.core_count fallback no hyperthreading
set_fact:
cpu_core_count: "{{ cpu_count }}"
when: 'cpu_core_per_socket is defined and cpu_core_per_socket == "Not Found" and not cpu_hyperthreading'
when: 'cpu_core_per_socket is defined and not cpu_core_per_socket and not cpu_hyperthreading'

- name: calculate cpu.core_count fallback with hyperthreading
set_fact:
cpu_core_count: "{{ (cpu_count | int) / 2 }}"
when: 'cpu_core_per_socket is defined and cpu_core_per_socket == "Not Found" and cpu_hyperthreading'
when: 'cpu_core_per_socket is defined and not cpu_core_per_socket and cpu_hyperthreading'

- name: default cpu.core_count to error if it doesn't exists
set_fact:
cpu_core_count: "error"
cpu_core_count: ""
when: 'cpu_core_count is not defined'
6 changes: 3 additions & 3 deletions roles/date/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

- name: extract result value for date.anaconda_log
set_fact:
date_anaconda_log: "{{ internal_date_anaconda_log_cmd['stdout'] | trim | default('error') }}"
date_anaconda_log: "{{ internal_date_anaconda_log_cmd['stdout'] | trim | default('') }}"
when: '"stdout" in internal_date_anaconda_log_cmd'

- name: handle failure value for date.anaconda_log
set_fact:
date_anaconda_log: "error"
date_anaconda_log: ""
when: '"stdout" not in internal_date_anaconda_log_cmd'

- name: gather date.machine_id fact
Expand All @@ -41,5 +41,5 @@

- name: extract result value for date.yum_history
set_fact:
date_yum_history: "{{ internal_date_yum_history_cmd['stdout_lines'] | select | first | default(None) if internal_have_yum else 'N/A (yum not found)' }}"
date_yum_history: "{{ internal_date_yum_history_cmd['stdout_lines'] | select | first | default('') if internal_have_yum else '' }}"
when: '"stdout_lines" in internal_date_yum_history_cmd'
20 changes: 10 additions & 10 deletions roles/dmi/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

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

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

- name: gather dmi.bios-version fact
Expand All @@ -24,12 +24,12 @@

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

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

- name: gather dmi.system-manufacturer fact
Expand All @@ -40,12 +40,12 @@

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

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

- name: gather dmi.processor-family fact
Expand All @@ -56,12 +56,12 @@

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

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

- name: gather dmi.system-uuid fact
Expand All @@ -72,10 +72,10 @@

- name: extract result value for dmi.system-uuid
set_fact:
dmi_system_uuid: "{{ internal_dmi_system_uuid_cmd['stdout'] | trim | default('error') if internal_have_dmidecode else 'N/A (dmidecode not found)' }}"
dmi_system_uuid: "{{ internal_dmi_system_uuid_cmd['stdout'] | trim | default('') if internal_have_dmidecode else '' }}"
when: '"stdout" in internal_dmi_system_uuid_cmd'

- name: handle failure value for dmi.system-uuid
set_fact:
dmi_system_uuid: "{{ 'error' if internal_have_dmidecode else 'N/A (dmidecode not found)' }}"
dmi_system_uuid: ""
when: '"stdout" not in internal_dmi_system_uuid_cmd'
2 changes: 1 addition & 1 deletion roles/redhat_packages/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@

- name: extract result value for redhat-packages.certs
set_fact:
redhat_packages_certs: '{{ internal_redhat_packages_certs_cmd | json_query("stdout") | trim | default("error") }}'
redhat_packages_certs: '{{ internal_redhat_packages_certs_cmd | json_query("stdout") | trim | default("") }}'
when: '"stdout" in internal_redhat_packages_certs_cmd'
6 changes: 3 additions & 3 deletions roles/redhat_release/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

- name: initialize redhat_release facts
set_fact:
redhat_release_name: 'N/A (rpm not found)'
redhat_release_version: 'N/A (rpm not found)'
redhat_release_release: 'N/A (rpm not found)'
redhat_release_name: ''
redhat_release_version: ''
redhat_release_release: ''

- name: gather internal_redhat_release fact
raw: rpm -q --queryformat "%{NAME}\n%{VERSION}\n%{RELEASE}\n" --whatprovides redhat-release
Expand Down
12 changes: 6 additions & 6 deletions roles/uname/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

- name: add uname.os to dictionary
set_fact:
uname_os: "{{ uname_os | json_query('stdout_lines[0]') | default('error') }}"
uname_os: "{{ uname_os | json_query('stdout_lines[0]') | default('') }}"

- name: gather uname.hostname fact
raw: uname -n
Expand All @@ -16,7 +16,7 @@

- name: add uname.hostname to dictionary
set_fact:
uname_hostname: "{{ uname_hostname | json_query('stdout_lines[0]') | default('error') }}"
uname_hostname: "{{ uname_hostname | json_query('stdout_lines[0]') | default('') }}"

- name: gather uname.processor fact
raw: uname -p
Expand All @@ -25,7 +25,7 @@

- name: add uname.processor to dictionary
set_fact:
uname_processor: "{{ uname_processor | json_query('stdout_lines[0]') | default('error') }}"
uname_processor: "{{ uname_processor | json_query('stdout_lines[0]') | default('') }}"

- name: gather uname.kernel fact
raw: uname -r
Expand All @@ -34,7 +34,7 @@

- name: add uname.kernel to dictionary
set_fact:
uname_kernel: "{{ uname_kernel | json_query('stdout_lines[0]') | default('error') }}"
uname_kernel: "{{ uname_kernel | json_query('stdout_lines[0]') | default('') }}"

- name: gather uname.all fact
raw: uname -a
Expand All @@ -43,7 +43,7 @@

- name: add uname.all to dictionary
set_fact:
uname_all: "{{ uname_all | json_query('stdout_lines[0]') | default('error') }}"
uname_all: "{{ uname_all | json_query('stdout_lines[0]') | default('') }}"

- name: gather uname.hardware_platform fact
raw: uname -i
Expand All @@ -52,4 +52,4 @@

- name: add uname.hardware_platform to dictionary
set_fact:
uname_hardware_platform: "{{ uname_hardware_platform | json_query('stdout_lines[0]') | default('error') }}"
uname_hardware_platform: "{{ uname_hardware_platform | json_query('stdout_lines[0]') | default('') }}"
4 changes: 2 additions & 2 deletions roles/virt/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@
when: 'internal_have_dmidecode and internal_sys_manu_kvm == "Y"'

- name: set virt.virt when dmidecode is not found
set_fact: virt_virt='N/A (dmidecode not found)'
set_fact: virt_virt=''
when: not internal_have_dmidecode

- name: set virt.type when dmidecode is not found
set_fact: virt_type='N/A (dmidecode not found)'
set_fact: virt_type=''
when: not internal_have_dmidecode

- name: set virt.virt fact due to internal_xen_guest
Expand Down
2 changes: 1 addition & 1 deletion roles/virt_what/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---

- name: set virt-what.type fact if virt-what not found
set_fact: virt_what_type='N/A (virt-what not found)'
set_fact: virt_what_type=''
when: 'not internal_have_virt_what'

- name: execute virt-what
Expand Down

0 comments on commit 36efb90

Please sign in to comment.