mirror of
				https://github.com/ansible-collections/community.general.git
				synced 2024-09-14 20:13:21 +02:00 
			
		
		
		
	The search string used to look for Clear Linux
was changed in 45a9f96774 to
be more specific, but was too specific. Now finding
a substring match for 'Clear Linux' in /usr/lib/os-release
is enough to consider a match.
Since the details of the full name in os-release varies
('Clear Linux Software for Intel Architecture',
 'Clear Linux OS for Intel Architecture', etc) the
search string match was failing and would fall back to the
'first word in the release file' method resulting in
ansible_distribution='NAME="Clear'
Also add a meta fact indicating which search string
was matched.
Test case info from:
        https://github.com/ansible/ansible/issues/31501#issuecomment-340861535
Fixes #31501
		
	
			
		
			
				
	
	
		
			77 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
			
		
		
	
	
			77 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable file
		
	
	
	
	
| #!/usr/bin/env python
 | |
| 
 | |
| """
 | |
| This script generated test_cases for test_distribution_version.py.
 | |
| 
 | |
| To do so it outputs the relevant files from /etc/*release, the output of platform.dist() and the current ansible_facts regarding the distribution version.
 | |
| 
 | |
| This assumes a working ansible version in the path.
 | |
| """
 | |
| 
 | |
| import platform
 | |
| import os.path
 | |
| import subprocess
 | |
| import json
 | |
| import sys
 | |
| 
 | |
| filelist = [
 | |
|     '/etc/oracle-release',
 | |
|     '/etc/slackware-version',
 | |
|     '/etc/redhat-release',
 | |
|     '/etc/vmware-release',
 | |
|     '/etc/openwrt_release',
 | |
|     '/etc/system-release',
 | |
|     '/etc/alpine-release',
 | |
|     '/etc/release',
 | |
|     '/etc/arch-release',
 | |
|     '/etc/os-release',
 | |
|     '/etc/SuSE-release',
 | |
|     '/etc/gentoo-release',
 | |
|     '/etc/os-release',
 | |
|     '/etc/lsb-release',
 | |
|     '/etc/altlinux-release',
 | |
|     '/etc/os-release',
 | |
|     '/etc/coreos/update.conf',
 | |
|     '/usr/lib/os-release',
 | |
| ]
 | |
| 
 | |
| fcont = {}
 | |
| 
 | |
| for f in filelist:
 | |
|     if os.path.exists(f):
 | |
|         s = os.path.getsize(f)
 | |
|         if s > 0 and s < 10000:
 | |
|             with open(f) as fh:
 | |
|                 fcont[f] = fh.read()
 | |
| 
 | |
| dist = platform.dist()
 | |
| 
 | |
| 
 | |
| facts = ['distribution', 'distribution_version', 'distribution_release', 'distribution_major_version', 'os_family']
 | |
| 
 | |
| try:
 | |
|     ansible_out = subprocess.check_output(
 | |
|         ['ansible', 'localhost', '-m', 'setup'])
 | |
| except subprocess.CalledProcessError as e:
 | |
|     print("ERROR: ansible run failed, output was: \n")
 | |
|     print(e.output)
 | |
|     sys.exit(e.returncode)
 | |
| 
 | |
| parsed = json.loads(ansible_out[ansible_out.index('{'):])
 | |
| ansible_facts = {}
 | |
| for fact in facts:
 | |
|     try:
 | |
|         ansible_facts[fact] = parsed['ansible_facts']['ansible_' + fact]
 | |
|     except:
 | |
|         ansible_facts[fact] = "N/A"
 | |
| 
 | |
| nicename = ansible_facts['distribution'] + ' ' + ansible_facts['distribution_version']
 | |
| 
 | |
| output = {
 | |
|     'name': nicename,
 | |
|     'input': fcont,
 | |
|     'platform.dist': dist,
 | |
|     'result': ansible_facts,
 | |
| }
 | |
| 
 | |
| print(json.dumps(output, indent=4))
 |