Repository: ansible/ansible

Issue:
iosxr_facts gathering memory summary broken
<!---
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 -->
module/network/iosxr/iosxr_facts
##### ANSIBLE VERSION
<!--- Paste verbatim output from “ansible --version” between quotes below -->
```
ansible 2.3.0.0 (stable-2.3 f66852f1ef) last updated 2017/04/18 08:24:40 (GMT +000)
  config file = /root/bachelor/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

```

##### CONFIGURATION
<!---
Mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
Not relevant
##### 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.
-->
N/A
##### SUMMARY
<!--- Explain the problem briefly -->
iosxr_facts does not gather memory summary from router when gathering the hardware subset
##### 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
- name: Get iosXR facts
  hosts: xxxx
  connection: local
  tasks:

    - name: gather facts
      iosxr_facts:
        provider: "{{ router_provider }}"
        gather_subset: "hardware"

```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Getting the facts "memtotal_mb" and "memfree_mb"
##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
The facts doesn't exist (the module doesn't fail)
<!--- Paste verbatim command output between quotes below -->

I've found the error, and it's caused by a broken regex, which when fixed breaks the module because the event in the if condition is also broken:
```
        match = re.search(r'Physical Memory (\d+)M total \((\d+)',
            results['show memory summary'])
        if match:
            self.facts['memtotal_mb'] = int(match[0])
            self.facts['memfree_mb'] = int(match[1])
```
this works if it looks like this:
```
        match = re.search(r'Physical Memory: (\d+)M total \((\d+)',
            results['show memory summary'])
        if match:
            self.facts['memtotal_mb'] = match.group(1)
            self.facts['memfree_mb'] = match.group(2)
```


Discussion:
cc @privateip @rcarrillocruz
[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: notify --->

Resolving patch:
diff --git a/lib/ansible/modules/network/iosxr/iosxr_facts.py b/lib/ansible/modules/network/iosxr/iosxr_facts.py
--- a/lib/ansible/modules/network/iosxr/iosxr_facts.py
+++ b/lib/ansible/modules/network/iosxr/iosxr_facts.py
@@ -174,11 +174,11 @@ def populate(self, results):
         self.facts['filesystems'] = self.parse_filesystems(
             results['dir /all'])
 
-        match = re.search(r'Physical Memory (\d+)M total \((\d+)',
+        match = re.search(r'Physical Memory: (\d+)M total \((\d+)',
             results['show memory summary'])
         if match:
-            self.facts['memtotal_mb'] = int(match[0])
-            self.facts['memfree_mb'] = int(match[1])
+            self.facts['memtotal_mb'] = match.group(1)
+            self.facts['memfree_mb'] = match.group(2)
 
     def parse_filesystems(self, data):
         return re.findall(r'^Directory of (\S+)', data, re.M)


Test patch: