Repository: ansible/ansible

Issue:
Incorrect ansible_pkg_mgr for ALT Linux target (`apt` instead of `apt_rpm`)
##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
module_utils/facts

##### ANSIBLE VERSION
```
ansible 2.5.0
  config file = /home/gross/.ansible.cfg
  configured module search path = [u'/home/gross/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.14 (default, Jan  5 2018, 10:41:29) [GCC 7.2.1 20171224]
```

##### CONFIGURATION
```
ANSIBLE_PIPELINING(/home/gross/.ansible.cfg) = True
ANSIBLE_SSH_ARGS(/home/gross/.ansible.cfg) = -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey
CACHE_PLUGIN(/home/gross/.ansible.cfg) = jsonfile
CACHE_PLUGIN_CONNECTION(/home/gross/.ansible.cfg) = ~/.ansible/facts-cache
CACHE_PLUGIN_TIMEOUT(/home/gross/.ansible.cfg) = 28800
DEFAULT_GATHERING(/home/gross/.ansible.cfg) = smart
DEFAULT_GATHER_SUBSET(/home/gross/.ansible.cfg) = network
DEFAULT_HOST_LIST(/home/gross/.ansible.cfg) = [u'/home/gross/work/_masked_/servers-dev']
DEFAULT_MODULE_NAME(/home/gross/.ansible.cfg) = shell
DEFAULT_REMOTE_USER(/home/gross/.ansible.cfg) = root
RETRY_FILES_ENABLED(/home/gross/.ansible.cfg) = False
```

##### OS / ENVIRONMENT
Host: ArchLinux
Target: AltLinux 8

##### SUMMARY
`ansible_pkg_mgs` is detected incorrectly for AltLinux hosts. Since `apt-get` is used as frontend ansible detects package manager as `apt` when `apt_rpm` should be detected instead.

##### STEPS TO REPRODUCE
Use target host with ALT Linux.

```
ansible all -m setup -a filter=ansible_distribution*
ansible all -m setup -a filter=ansible_pkg_mgr
```

##### EXPECTED RESULTS
```json
host | SUCCESS => {
    "ansible_facts": {
        "ansible_distribution": "ALT", 
        "ansible_distribution_file_parsed": true, 
        "ansible_distribution_file_path": "/etc/redhat-release", 
        "ansible_distribution_file_variety": "RedHat", 
        "ansible_distribution_major_version": "8", 
        "ansible_distribution_release": "NA", 
        "ansible_distribution_version": "8.0"
    }, 
    "changed": false
}
host | SUCCESS => {
    "ansible_facts": {
        "ansible_pkg_mgr": "apt_rpm"
    }, 
    "changed": false
}
```

##### ACTUAL RESULTS
```json
host | SUCCESS => {
    "ansible_facts": {
        "ansible_distribution": "ALT", 
        "ansible_distribution_file_parsed": true, 
        "ansible_distribution_file_path": "/etc/redhat-release", 
        "ansible_distribution_file_variety": "RedHat", 
        "ansible_distribution_major_version": "8", 
        "ansible_distribution_release": "NA", 
        "ansible_distribution_version": "8.0"
    }, 
    "changed": false
}
host | SUCCESS => {
    "ansible_facts": {
        "ansible_pkg_mgr": "apt"
    }, 
    "changed": false
}
```


Discussion:
Files identified in the description:
None

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->
@ansibot !component module_utils/facts
Files identified in the description:
* [lib/ansible/module_utils](https://github.com/ansible/ansible/blob/devel/lib/ansible/module_utils)

If these files are inaccurate, please update the `component name` section of the description or use the `!component` bot command.

[click here for bot help](https://github.com/ansible/ansibullbot/blob/master/ISSUE_HELP.md)
<!--- boilerplate: components_banner --->

Resolving patch:
diff --git a/lib/ansible/module_utils/facts/system/pkg_mgr.py b/lib/ansible/module_utils/facts/system/pkg_mgr.py
--- a/lib/ansible/module_utils/facts/system/pkg_mgr.py
+++ b/lib/ansible/module_utils/facts/system/pkg_mgr.py
@@ -78,5 +78,10 @@ def collect(self, module=None, collected_facts=None):
             if os.path.exists(pkg['path']):
                 pkg_mgr_name = pkg['name']
 
+        if pkg_mgr_name == 'apt' and \
+                os.path.exists('/usr/bin/rpm') and \
+                not os.path.exists('/usr/bin/dpkg'):
+            pkg_mgr_name = 'apt_rpm'
+
         facts_dict['pkg_mgr'] = pkg_mgr_name
         return facts_dict


Test patch: