Repository: ansible/ansible

Issue:
HP-UX hardware facts fail on virtualized ia64
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report


##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
facts/hardware/hpux.py
##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.4.0

also affects facts.py in 2.1, 2.2, 2.3
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->
Managing Virtualized HPUX ia64
##### SUMMARY
<!--- Explain the problem briefly -->
machinfo returns questionable cpu data for virtualized ia64 systems.   Causes module failure in 2.1 through 2.3.   2.4 runs and is missing all hardware facts.
##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
ansible all -m setup -i hp1123VM-ia64server, -u root
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Should return list of hardware facts, including memtotal_mb, swaptotal_mb, firmware_version, product_serial.
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
All hardware facts are missing on 2.4.   Module failure with traceback prior in 2.1-2.3.
<!--- Paste verbatim command output between quotes below -->
```
From 2.2:

| FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Warning: Permanently added 't' (RSA) to the list of known hosts.\r\nTraceback (most recent call last):\n  File \"/tmp/ansible_vA4QLB/ansible_module_setup.py\", line 134, in <module>\n    main()\n  File \"/tmp/ansible_vA4QLB/ansible_module_setup.py\", line 126, in main\n    data = get_all_facts(module)\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3518, in get_all_facts\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3461, in ansible_facts\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 2002, in populate\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 2015, in get_cpu_facts\nIndexError: list index out of range\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE"
}
```

HP-UX hardware facts fail on virtualized ia64
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest: -->
 - Bug Report


##### COMPONENT NAME
<!--- Name of the module/plugin/task/feature -->
facts/hardware/hpux.py
##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
2.4.0

also affects facts.py in 2.1, 2.2, 2.3
```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say “N/A” for anything that is not platform-specific.
-->
Managing Virtualized HPUX ia64
##### SUMMARY
<!--- Explain the problem briefly -->
machinfo returns questionable cpu data for virtualized ia64 systems.   Causes module failure in 2.1 through 2.3.   2.4 runs and is missing all hardware facts.
##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->

<!--- Paste example playbooks or commands between quotes below -->
```yaml
ansible all -m setup -i hp1123VM-ia64server, -u root
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Should return list of hardware facts, including memtotal_mb, swaptotal_mb, firmware_version, product_serial.
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
All hardware facts are missing on 2.4.   Module failure with traceback prior in 2.1-2.3.
<!--- Paste verbatim command output between quotes below -->
```
From 2.2:

| FAILED! => {
    "changed": false,
    "failed": true,
    "module_stderr": "Warning: Permanently added 't' (RSA) to the list of known hosts.\r\nTraceback (most recent call last):\n  File \"/tmp/ansible_vA4QLB/ansible_module_setup.py\", line 134, in <module>\n    main()\n  File \"/tmp/ansible_vA4QLB/ansible_module_setup.py\", line 126, in main\n    data = get_all_facts(module)\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3518, in get_all_facts\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 3461, in ansible_facts\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 2002, in populate\n  File \"/tmp/ansible_vA4QLB/ansible_modlib.zip/ansible/module_utils/facts.py\", line 2015, in get_cpu_facts\nIndexError: list index out of range\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE"
}
```



Discussion:
This appears to be the same bug you reported in https://github.com/ansible/ansible/issues/25365

Any reason we can't use a single bug report?
This appears to be the same bug you reported in https://github.com/ansible/ansible/issues/25365

Any reason we can't use a single bug report?

Resolving patch:
diff --git a/lib/ansible/module_utils/facts/hardware/hpux.py b/lib/ansible/module_utils/facts/hardware/hpux.py
--- a/lib/ansible/module_utils/facts/hardware/hpux.py
+++ b/lib/ansible/module_utils/facts/hardware/hpux.py
@@ -62,9 +62,11 @@ def get_cpu_facts(self, collected_facts=None):
         elif collected_facts.get('ansible_architecture') == 'ia64':
             if collected_facts.get('ansible_distribution_version') == "B.11.23":
                 rc, out, err = self.module.run_command("/usr/contrib/bin/machinfo | grep 'Number of CPUs'", use_unsafe_shell=True)
-                cpu_facts['processor_count'] = int(out.strip().split('=')[1])
+                if out:
+                    cpu_facts['processor_count'] = int(out.strip().split('=')[1])
                 rc, out, err = self.module.run_command("/usr/contrib/bin/machinfo | grep 'processor family'", use_unsafe_shell=True)
-                cpu_facts['processor'] = re.search('.*(Intel.*)', out).groups()[0].strip()
+                if out:
+                    cpu_facts['processor'] = re.search('.*(Intel.*)', out).groups()[0].strip()
                 rc, out, err = self.module.run_command("ioscan -FkCprocessor | wc -l", use_unsafe_shell=True)
                 cpu_facts['processor_cores'] = int(out.strip())
             if collected_facts.get('ansible_distribution_version') == "B.11.31":


Test patch: