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

Commit

Permalink
Better error messages for missing programs
Browse files Browse the repository at this point in the history
Check whether programs we need (like dmidecode and tune2fs) are
present on the remote machine before running commands that depend on
them. If they aren't present, we give report messages like "N/A
(dmidecode not found)" instead of propagating a shell error message to
the output.

This also adds a file to the documentation listing exactly what
executables are needed for each set of facts. We do not explicitly
check for standard Unix things like grep and sed, so if those are
missing we would still give a shell error, but the documentation lists
all of the programs we need.
  • Loading branch information
Noah Lavine committed Sep 1, 2017
1 parent 619d800 commit 94ac3eb
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 83 deletions.
10 changes: 10 additions & 0 deletions doc/command_syntax_usage.rst
Expand Up @@ -217,3 +217,13 @@ If the scan user uses a password to sudo, one can be given with the
`--sudo-password` option to the `auth add` and `auth edit`
commands. The sudo-with-password fundtionality can be tested by using
the 'askpass' box in the Vagrantfile.

^^^^^^^^^^^^^^^^^^^^^^^^^^^
Programs on Remote Machines
^^^^^^^^^^^^^^^^^^^^^^^^^^^

Besides standard Unix utilities, some Rho fact collectors depend on
specific programs being installed on the machines being scanned. THe
complete list is at `remote programs
<github.com/quipucords/rho/doc/remote_programs.rst>`.

79 changes: 79 additions & 0 deletions doc/remote_programs.rst
@@ -0,0 +1,79 @@
---------------
Remote Programs
---------------

This file documents which programs on the remote host are used to
collect different groups of facts. **bold** is used for executables
that are not standard Unix programs (i.e. not grep, sed, etc.). In
addition to the programs below, we depend on standard shell facilities
like those provided by bash.

- brms.*
- find
- sed
- sort
- grep / egrep
- cpu.*
- cat
- grep
- sed
- wc
- **/usr/sbin/dmidecode**
- date.*
- date
- ls
- grep / egrep
- **tune2fs**
- mount
- sed
- **yum**
- tail
- dmi.*
- **/usr/sbin/dmidecode**
- grep
- sed
- etc_release.*
- cat
- uname
- file_contents.*
- cat
- jboss.fuse.*
- find
- sed
- sort
- echo
- jboss.* (facts one level down from jboss)
- find
- grep
- **java**
- sed
- stat
- df
- tail
- ls
- sort
- redhat_packages
- **rpm**
- redhat_release.*
- **rpm**
- subman.*
- **subscription-manager**
- grep
- sed
- ls
- wc
- uname.*
- uname
- virt.*
- command
- **virsh**
- ps
- grep
- wc
- **/usr/sbin/dmidecode**
- sed
- cat
- virt_what.*
- command
- **virt-what**
- echo
15 changes: 10 additions & 5 deletions library/spit_results.py
Expand Up @@ -144,6 +144,8 @@ def safe_next(iterator):
def process_jboss_versions(host_vars):
"""Get JBoss version information from the host_vars."""

running_ver = 'jboss.running-versions'

lines = []
val = {}

Expand All @@ -156,7 +158,6 @@ def process_jboss_versions(host_vars):
if 'jboss.run-jar-ver' in host_vars:
lines.extend(host_vars['jboss.run-jar-ver']['stdout_lines'])
if 'jboss.running-versions' in host_vars:
running_ver = 'jboss.running-versions'
val[running_ver] = host_vars[running_ver]['stdout']

jboss_releases = []
Expand All @@ -172,11 +173,15 @@ def process_jboss_versions(host_vars):
elif version.strip():
jboss_releases.append('Unknown-Release: ' + version)

if not jboss_releases:
return val
if jboss_releases:
val['jboss.installed-versions'] = '; '.join(jboss_releases)
val['jboss.deploy-dates'] = '; '.join(deploy_dates)

if not host_vars['have_java']:
val['jboss.installed-versions'] = 'N/A (java not found)'
val['jboss.deploy-dates'] = 'N/A (java not found)'
val[running_ver] = 'N/A (java not found)'

val['jboss.installed-versions'] = '; '.join(jboss_releases)
val['jboss.deploy-dates'] = '; '.join(deploy_dates)
return val


Expand Down
1 change: 1 addition & 0 deletions rho_playbook.yml
Expand Up @@ -8,6 +8,7 @@
hosts: all
gather_facts: no
roles:
- check_for_programs
- connection
- cpu
- date
Expand Down
73 changes: 73 additions & 0 deletions roles/check_for_programs/tasks/main.yml
@@ -0,0 +1,73 @@
---

- name: gather have_dmidecode_raw
raw: command -v /usr/sbin/dmidecode
register: have_dmidecode_raw
ignore_errors: yes

- name: set have_dmidecode
set_fact:
have_dmidecode: "{{ have_dmidecode_raw.rc == 0 }}"

- name: gather have_tune2fs_raw
raw: command -v tune2fs
register: have_tune2fs_raw
ignore_errors: yes

- name: set have_tune2fs
set_fact:
have_tune2fs: "{{ have_tune2fs_raw.rc == 0 }}"

- name: gather have_yum_raw
raw: command -v yum
register: have_yum_raw
ignore_errors: yes

- name: set have_yum
set_fact:
have_yum: "{{ have_yum_raw.rc == 0 }}"

- name: gather have_java_raw
raw: command -v java
register: have_java_raw
ignore_errors: yes

- name: set have_java
set_fact:
have_java: "{{ have_java_raw.rc == 0 }}"

- name: gather have_rpm_raw
raw: command -v rpm
register: have_rpm_raw
ignore_errors: yes

- name: set have_rpm
set_fact:
have_rpm: "{{ have_rpm_raw.rc == 0 }}"

- name: gather have_subscription_manager_raw
raw: command -v subscription-manager
register: have_subscription_manager_raw
ignore_errors: yes

- name: set have_subscription_manager
set_fact:
have_subscription_manager: "{{ have_subscription_manager_raw.rc == 0 }}"

- name: gather have_virsh_raw
raw: command -v virsh
register: have_virsh_raw
ignore_errors: yes

- name: set have_virsh
set_fact:
have_virsh: "{{ have_virsh_raw.rc == 0 }}"

- name: gather have_virt_what_raw
raw: command -v virt-what
register: have_virt_what_raw
ignore_errors: yes

- name: set have_virt_what
set_fact:
have_virt_what: "{{ have_virt_what_raw.rc == 0 }}"
4 changes: 2 additions & 2 deletions roles/cpu/tasks/main.yml
Expand Up @@ -87,11 +87,11 @@
register: cpu_socket_count
become: yes
ignore_errors: yes
when: '"cpu.socket_count" in facts_to_collect'
when: 'have_dmidecode and "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'] | trim | default('error') }) }}"
cpu: "{{ cpu|default({}) | combine({ item: cpu_socket_count['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }) }}"
with_items:
- 'cpu.socket_count'
when: '"cpu.socket_count" in facts_to_collect'
8 changes: 4 additions & 4 deletions roles/date/tasks/main.yml
Expand Up @@ -48,11 +48,11 @@
raw: fs_date=$(tune2fs -l $(mount | egrep '/ type' | grep -o '/dev.* on' | sed -e 's/\on//g') | grep 'Filesystem created' | sed 's/Filesystem created:\s*//g'); if [[ $fs_date ]]; then date +'%F' -d \"$fs_date\"; else echo "" ; fi
register: date_filesystem_create
ignore_errors: yes
when: '"date.filesystem_create" in facts_to_collect'
when: 'have_tune2fs and "date.filesystem_create" in facts_to_collect'

- name: add date.filesystem_create to dictionary
set_fact:
date: "{{ date|default({}) | combine({ item: date_filesystem_create['stdout_lines'][0] | default('error') }) }}"
date: "{{ date|default({}) | combine({ item: date_filesystem_create['stdout_lines'][0] | default('error') if have_tune2fs else 'N/A (tune2fs not found)' }) }}"
with_items:
- 'date.filesystem_create'
when: '"date.filesystem_create" in facts_to_collect'
Expand All @@ -62,11 +62,11 @@
register: date_yum_history
become: yes
ignore_errors: yes
when: '"date.yum_history" in facts_to_collect'
when: 'have_yum and "date.yum_history" in facts_to_collect'

- name: add date.yum_history to dictionary
set_fact:
date: "{{ date|default({}) | combine({ item: date_yum_history['stdout_lines'] | select | first | default('error') }) }}"
date: "{{ date|default({}) | combine({ item: date_yum_history['stdout_lines'] | select | first | default('error') if have_yum else 'N/A (yum not found)' }) }}"
with_items:
- 'date.yum_history'
when: '"date.yum_history" in facts_to_collect'
8 changes: 4 additions & 4 deletions roles/dmi/tasks/main.yml
Expand Up @@ -13,7 +13,7 @@

- name: add dmi.bios-vendor to dictionary
set_fact:
dmi: "{{ dmi|default({}) | combine({ item: dmi_bios_vendor['stdout'] | trim | default('error') }) }}"
dmi: "{{ dmi|default({}) | combine({ item: dmi_bios_vendor['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }) }}"
with_items:
- 'dmi.bios-vendor'
when: '"dmi.bios-vendor" in facts_to_collect'
Expand All @@ -27,7 +27,7 @@

- name: add dmi.bios-version to dictionary
set_fact:
dmi: "{{ dmi|default({}) | combine({ item: dmi_bios_version['stdout'] | trim | default('error') }) }}"
dmi: "{{ dmi|default({}) | combine({ item: dmi_bios_version['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }) }}"
with_items:
- 'dmi.bios-version'
when: '"dmi.bios-version" in facts_to_collect'
Expand All @@ -41,7 +41,7 @@

- name: add dmi.system-manufacturer to dictionary
set_fact:
dmi: "{{ dmi|default({}) | combine({ item: dmi_system_manufacturer['stdout'] | trim | default('error') }) }}"
dmi: "{{ dmi|default({}) | combine({ item: dmi_system_manufacturer['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }) }}"
with_items:
- 'dmi.system-manufacturer'
when: '"dmi.system-manufacturer" in facts_to_collect'
Expand All @@ -55,7 +55,7 @@

- name: add dmi.processor-family to dictionary
set_fact:
dmi: "{{ dmi|default({}) | combine({ item: dmi_processor_family['stdout'] | trim | default('error') }) }}"
dmi: "{{ dmi|default({}) | combine({ item: dmi_processor_family['stdout'] | trim | default('error') if have_dmidecode else 'N/A (dmidecode not found)' }) }}"
with_items:
- 'dmi.processor-family'
when: '"dmi.processor-family" in facts_to_collect'
6 changes: 3 additions & 3 deletions roles/jboss/tasks/main.yml
Expand Up @@ -5,16 +5,16 @@
raw: FOUND=""; for jar in `find / -name 'jboss-modules.jar' 2>/dev/null | grep -v '\.installation/patches'`; do VERSION=$(java -jar ${jar} -version 2> /dev/null | grep version | sed 's/.*version\s//g'); inode=$(stat -c '%i' "${jar}"); fs=$(df -T "${jar}" | grep "/dev" | sed 's/ .*//'); ctime=$(stat ${jar} | grep 'Change' | grep -oP '[1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]'); if [ ! -z "${VERSION}" ]; then if [ ! -z "$FOUND" ]; then FOUND="$FOUND; $VERSION**$ctime"; else FOUND=${VERSION}'**'${ctime}; fi; fi; done; echo ${FOUND}
register: jboss.jar-ver
ignore_errors: yes
when: '"jboss.installed-versions" in facts_to_collect or "jboss.deploy-dates" in facts_to_collect'
when: 'have_java and ("jboss.installed-versions" in facts_to_collect or "jboss.deploy-dates" in facts_to_collect)'

- name: Gather jboss.run-jar-ver
raw: FOUND=""; for jar in `find / -name 'run.jar' 2>/dev/null`; do VERSION=$(java -jar ${jar} --version 2> /dev/null | grep build | sed 's/.*[CS]V[NS]Tag.//g' | sed 's/\sdate.*//g'); inode=$(stat -c '%i' "${jar}"); fs=$(df -T "${jar}" | tail -1 | sed 's/ .*//'); ctime=$(stat ${jar} | grep 'Change' | grep -oP '[1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]'); if [ ! -z "${VERSION}" ]; then if [ ! -z "$FOUND" ]; then FOUND="$FOUND; $VERSION**${ctime}"; else FOUND=${VERSION}'**'${ctime}; fi; fi; done; echo ${FOUND};
register: jboss.run-jar-ver
ignore_errors: yes
when: '"jboss.installed-versions" in facts_to_collect or "jboss.deploy-dates" in facts_to_collect'
when: 'have_java and ("jboss.installed-versions" in facts_to_collect or "jboss.deploy-dates" in facts_to_collect)'

- name: Gather jboss.running-versions
raw: for proc_pid in $(find /proc -maxdepth 1 -name "[0-9]*"); do ls -l ${proc_pid}/fd 2>/dev/null | grep "java"; done | grep -e "/modules/system/layers/base\|/opt/rh/eap" | sed -n "s/.*\->//p" | sed -n 's/\/modules\/system\/layers\/base.*//p;s/.*\(\/opt\/rh\/eap[1-9]\).*/\1/p' | sort -u
register: jboss.running-versions
ignore_errors: yes
when: '"jboss.running-versions" in facts_to_collect'
when: 'have_java and "jboss.running-versions" in facts_to_collect'
4 changes: 2 additions & 2 deletions roles/redhat_packages/tasks/main.yml
Expand Up @@ -68,11 +68,11 @@
raw: rpm -qa --qf "%{NAME}|%{VERSION}|%{RELEASE}|%{INSTALLTIME}|%{VENDOR}|%{BUILDTIME}|%{BUILDHOST}|%{SOURCERPM}|%{LICENSE}|%{PACKAGER}|%{INSTALLTIME:date}|%{BUILDTIME:date}\n"
register: redhat_packages_results
ignore_errors: yes
when: gather_redhat_packages
when: have_rpm and gather_redhat_packages

- name: add redhat-packages.results to dictionary
set_fact:
redhat_packages: "{{ redhat_packages|default({}) | combine({ item: redhat_packages_results['stdout_lines'] | default([]) }) }}"
redhat_packages: "{{ redhat_packages|default({}) | combine({ item: redhat_packages_results['stdout_lines'] | default([]) if have_rpm else 'N/A (rpm not found)' }) }}"
with_items:
- 'redhat-packages.results'
when: gather_redhat_packages
8 changes: 4 additions & 4 deletions roles/redhat_release/tasks/main.yml
Expand Up @@ -8,11 +8,11 @@
raw: rpm -q --queryformat "%{NAME}\n" --whatprovides redhat-release
register: redhat_release_name
ignore_errors: yes
when: '"redhat-release.name" in facts_to_collect'
when: 'have_rpm and "redhat-release.name" in facts_to_collect'

- name: add redhat-release.name to dictionary
set_fact:
redhat_release: "{{ redhat_release|default({}) | combine({ item: redhat_release_name['stdout_lines'][0] | default('error') }) }}"
redhat_release: "{{ redhat_release|default({}) | combine({ item: redhat_release_name['stdout_lines'][0] | default('error') if have_rpm else 'N/A (rpm not found)' }) }}"
with_items:
- 'redhat-release.name'
when: '"redhat-release.name" in facts_to_collect'
Expand All @@ -25,7 +25,7 @@

- name: add redhat-release.version to dictionary
set_fact:
redhat_release: "{{ redhat_release|default({}) | combine({ item: redhat_release_version['stdout_lines'][0] | default('error') }) }}"
redhat_release: "{{ redhat_release|default({}) | combine({ item: redhat_release_version['stdout_lines'][0] | default('error') if have_rpm else 'N/A (rpm not found)' }) }}"
with_items:
- 'redhat-release.version'
when: '"redhat-release.version" in facts_to_collect'
Expand All @@ -38,7 +38,7 @@

- name: add redhat-release.release to dictionary
set_fact:
redhat_release: "{{ redhat_release|default({}) | combine({ item: redhat_release_release['stdout_lines'][0] | default('error') }) }}"
redhat_release: "{{ redhat_release|default({}) | combine({ item: redhat_release_release['stdout_lines'][0] | default('error') if have_rpm else 'N/A (rpm not found)' }) }}"
with_items:
- 'redhat-release.release'
when: '"redhat-release.release" in facts_to_collect'

0 comments on commit 94ac3eb

Please sign in to comment.