mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
facts: solaris: introduce distribution_major version detection for Solaris (#43978)
* facts: solaris: introduce distribution_major version detection for Solaris Currently, there's no distribution_major in facts module on Solaris OS. Use "uname -r" output to report major version. Before the patch we get this on Solaris 11.3 : $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {}, "changed": false} and after this patch, output is the following: $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {"ansible_distribution_major_version": "11"}, "changed": false} Tested with Solaris 11.3 and Solaris 10 (both are x86_64 VMs) Includes patch for test/units. Fixes #18197 * Try to fix test unit * should work now... * fixes for W291 (trailing whitespace) and E265 (block comment) * mock uname_release for solaris 10 and solaris 11 * facts: solaris: introduce distribution_major version detection for Solaris Currently, there's no distribution_major in facts module on Solaris OS. Use "uname -r" output to report major version. Before the patch we get this on Solaris 11.3 : $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {}, "changed": false} and after this patch, output is the following: $ ansible -o solaris11 -m setup -a filter=ansible_distribution_major_version solaris11 | SUCCESS => {"ansible_facts": {"ansible_distribution_major_version": "11"}, "changed": false} Tested with Solaris 11.3 and Solaris 10 (both are x86_64 VMs) Includes patch for test/units. Fixes #18197 * Try to fix test unit * should work now... * fixes for W291 (trailing whitespace) and E265 (block comment) * mock uname_release for solaris 10 and solaris 11 * typo uname_v -> uname_r * rebase * fix pep8 E302: 2 blank lines * remove int() cast to match test case * use single function for uname_r and uname_v * add solaris 11.4 OS to distribution test unit * fix pep8 sanity - E231 missing whitespace * distribution_major_version variable strip newline * mocker test function for mock_get_uname with parameters instead of two different functions * failed to make one fuction with test unit, revert to use 2 different functions * try to use single get_uname function * fix pep8: E703
This commit is contained in:
parent
96b3ef5553
commit
fe8412128b
2 changed files with 51 additions and 8 deletions
|
@ -26,8 +26,12 @@ from ansible.module_utils.facts.utils import get_file_content
|
|||
from ansible.module_utils.facts.collector import BaseFactCollector
|
||||
|
||||
|
||||
def get_uname_version(module):
|
||||
rc, out, err = module.run_command(['uname', '-v'])
|
||||
def get_uname(module, flags=('-v')):
|
||||
if isinstance(flags, str):
|
||||
flags = flags.split()
|
||||
command = ['uname']
|
||||
command.extend(flags)
|
||||
rc, out, err = module.run_command(command)
|
||||
if rc == 0:
|
||||
return out
|
||||
return None
|
||||
|
@ -587,6 +591,8 @@ class Distribution(object):
|
|||
data = get_file_content('/etc/release').splitlines()[0]
|
||||
|
||||
if 'Solaris' in data:
|
||||
# for solaris 10 uname_r will contain 5.10, for solaris 11 it will have 5.11
|
||||
uname_r = get_uname(self.module, flags=['-r'])
|
||||
ora_prefix = ''
|
||||
if 'Oracle Solaris' in data:
|
||||
data = data.replace('Oracle ', '')
|
||||
|
@ -594,9 +600,10 @@ class Distribution(object):
|
|||
sunos_facts['distribution'] = data.split()[0]
|
||||
sunos_facts['distribution_version'] = data.split()[1]
|
||||
sunos_facts['distribution_release'] = ora_prefix + data
|
||||
sunos_facts['distribution_major_version'] = uname_r.split('.')[1].rstrip()
|
||||
return sunos_facts
|
||||
|
||||
uname_v = get_uname_version(self.module)
|
||||
uname_v = get_uname(self.module, flags=['-v'])
|
||||
distribution_version = None
|
||||
|
||||
if 'SmartOS' in data:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue