mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-06 06:04:24 -07:00
Using "OtherLinux" in module_commons, cleander detection in setup.
This commit is contained in:
parent
5646bc278b
commit
7129a9e355
2 changed files with 23 additions and 22 deletions
|
@ -99,7 +99,7 @@ def get_distribution():
|
||||||
distribution = platform.linux_distribution()[0].capitalize()
|
distribution = platform.linux_distribution()[0].capitalize()
|
||||||
if distribution == 'NA':
|
if distribution == 'NA':
|
||||||
if os.path.is_file('/etc/system-release'):
|
if os.path.is_file('/etc/system-release'):
|
||||||
distribution = 'Amazon'
|
distribution = 'OtherLinux'
|
||||||
except:
|
except:
|
||||||
# FIXME: MethodMissing, I assume?
|
# FIXME: MethodMissing, I assume?
|
||||||
distribution = platform.dist()[0].capitalize()
|
distribution = platform.dist()[0].capitalize()
|
||||||
|
@ -108,7 +108,7 @@ def get_distribution():
|
||||||
return distribution
|
return distribution
|
||||||
|
|
||||||
def load_platform_subclass(cls, *args, **kwargs):
|
def load_platform_subclass(cls, *args, **kwargs):
|
||||||
'''
|
'''
|
||||||
used by modules like User to have different implementations based on detected platform. See User
|
used by modules like User to have different implementations based on detected platform. See User
|
||||||
module for an example.
|
module for an example.
|
||||||
'''
|
'''
|
||||||
|
@ -116,7 +116,7 @@ def load_platform_subclass(cls, *args, **kwargs):
|
||||||
this_platform = get_platform()
|
this_platform = get_platform()
|
||||||
distribution = get_distribution()
|
distribution = get_distribution()
|
||||||
subclass = None
|
subclass = None
|
||||||
|
|
||||||
# get the most specific superclass for this platform
|
# get the most specific superclass for this platform
|
||||||
if distribution is not None:
|
if distribution is not None:
|
||||||
for sc in cls.__subclasses__():
|
for sc in cls.__subclasses__():
|
||||||
|
@ -174,7 +174,7 @@ class AnsibleModule(object):
|
||||||
self._log_invocation()
|
self._log_invocation()
|
||||||
|
|
||||||
def load_file_common_arguments(self, params):
|
def load_file_common_arguments(self, params):
|
||||||
'''
|
'''
|
||||||
many modules deal with files, this encapsulates common
|
many modules deal with files, this encapsulates common
|
||||||
options that the file module accepts such that it is directly
|
options that the file module accepts such that it is directly
|
||||||
available to all modules and they can share code.
|
available to all modules and they can share code.
|
||||||
|
@ -194,7 +194,7 @@ class AnsibleModule(object):
|
||||||
setype = params.get('setype', None)
|
setype = params.get('setype', None)
|
||||||
selevel = params.get('serange', 's0')
|
selevel = params.get('serange', 's0')
|
||||||
secontext = [seuser, serole, setype]
|
secontext = [seuser, serole, setype]
|
||||||
|
|
||||||
if self.selinux_mls_enabled():
|
if self.selinux_mls_enabled():
|
||||||
secontext.append(selevel)
|
secontext.append(selevel)
|
||||||
|
|
||||||
|
@ -204,9 +204,9 @@ class AnsibleModule(object):
|
||||||
secontext[i] = default_secontext[i]
|
secontext[i] = default_secontext[i]
|
||||||
|
|
||||||
return dict(
|
return dict(
|
||||||
path=path, mode=mode, owner=owner, group=group,
|
path=path, mode=mode, owner=owner, group=group,
|
||||||
seuser=seuser, serole=serole, setype=setype,
|
seuser=seuser, serole=serole, setype=setype,
|
||||||
selevel=selevel, secontext=secontext,
|
selevel=selevel, secontext=secontext,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -274,11 +274,11 @@ class AnsibleModule(object):
|
||||||
st = os.stat(filename)
|
st = os.stat(filename)
|
||||||
uid = st.st_uid
|
uid = st.st_uid
|
||||||
gid = st.st_gid
|
gid = st.st_gid
|
||||||
try:
|
try:
|
||||||
user = pwd.getpwuid(uid)[0]
|
user = pwd.getpwuid(uid)[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
user = str(uid)
|
user = str(uid)
|
||||||
try:
|
try:
|
||||||
group = grp.getgrgid(gid)[0]
|
group = grp.getgrgid(gid)[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
group = str(gid)
|
group = str(gid)
|
||||||
|
@ -293,7 +293,7 @@ class AnsibleModule(object):
|
||||||
def set_context_if_different(self, path, context, changed):
|
def set_context_if_different(self, path, context, changed):
|
||||||
|
|
||||||
if not HAVE_SELINUX or not self.selinux_enabled():
|
if not HAVE_SELINUX or not self.selinux_enabled():
|
||||||
return changed
|
return changed
|
||||||
cur_context = self.selinux_context(path)
|
cur_context = self.selinux_context(path)
|
||||||
new_context = list(cur_context)
|
new_context = list(cur_context)
|
||||||
# Iterate over the current context instead of the
|
# Iterate over the current context instead of the
|
||||||
|
@ -416,9 +416,9 @@ class AnsibleModule(object):
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
def add_path_info(self, kwargs):
|
def add_path_info(self, kwargs):
|
||||||
'''
|
'''
|
||||||
for results that are files, supplement the info about the file
|
for results that are files, supplement the info about the file
|
||||||
in the return path with stats about the file path.
|
in the return path with stats about the file path.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
path = kwargs.get('path', kwargs.get('dest', None))
|
path = kwargs.get('path', kwargs.get('dest', None))
|
||||||
|
@ -730,7 +730,7 @@ class AnsibleModule(object):
|
||||||
shell=shell,
|
shell=shell,
|
||||||
close_fds=close_fds,
|
close_fds=close_fds,
|
||||||
stdin=st_in,
|
stdin=st_in,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.PIPE)
|
stderr=subprocess.PIPE)
|
||||||
if data:
|
if data:
|
||||||
cmd.stdin.write(data)
|
cmd.stdin.write(data)
|
||||||
|
|
|
@ -31,13 +31,13 @@ DOCUMENTATION = '''
|
||||||
module: setup
|
module: setup
|
||||||
short_description: Gathers facts about remote hosts
|
short_description: Gathers facts about remote hosts
|
||||||
options: {}
|
options: {}
|
||||||
description:
|
description:
|
||||||
- This module is automatically called by playbooks to gather useful
|
- This module is automatically called by playbooks to gather useful
|
||||||
variables about remote hosts that can be used in playbooks. It can also be
|
variables about remote hosts that can be used in playbooks. It can also be
|
||||||
executed directly by C(/usr/bin/ansible) to check what variables are
|
executed directly by C(/usr/bin/ansible) to check what variables are
|
||||||
available to a host. Ansible provides many I(facts) about the system,
|
available to a host. Ansible provides many I(facts) about the system,
|
||||||
automatically.
|
automatically.
|
||||||
notes:
|
notes:
|
||||||
- More ansible facts will be added with successive releases. If I(facter) or
|
- More ansible facts will be added with successive releases. If I(facter) or
|
||||||
I(ohai) are installed, variables from these programs will also be snapshotted
|
I(ohai) are installed, variables from these programs will also be snapshotted
|
||||||
into the JSON file for usage in templating. These variables are prefixed
|
into the JSON file for usage in templating. These variables are prefixed
|
||||||
|
@ -77,7 +77,7 @@ class Facts(object):
|
||||||
# This is the fallback to handle unknowns or exceptions
|
# This is the fallback to handle unknowns or exceptions
|
||||||
OSDIST_DICT = { '/etc/redhat-release': 'RedHat',
|
OSDIST_DICT = { '/etc/redhat-release': 'RedHat',
|
||||||
'/etc/vmware-release': 'VMwareESX',
|
'/etc/vmware-release': 'VMwareESX',
|
||||||
'/etc/system-release': 'Amazon' }
|
'/etc/system-release': 'OtherLinux' }
|
||||||
SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' }
|
SELINUX_MODE_DICT = { 1: 'enforcing', 0: 'permissive', -1: 'disabled' }
|
||||||
|
|
||||||
# A list of dicts. If there is a platform with more than one
|
# A list of dicts. If there is a platform with more than one
|
||||||
|
@ -86,7 +86,7 @@ class Facts(object):
|
||||||
PKG_MGRS = [ { 'path' : '/usr/bin/yum', 'name' : 'yum' },
|
PKG_MGRS = [ { 'path' : '/usr/bin/yum', 'name' : 'yum' },
|
||||||
{ 'path' : '/usr/bin/apt-get', 'name' : 'apt' },
|
{ 'path' : '/usr/bin/apt-get', 'name' : 'apt' },
|
||||||
{ 'path' : '/usr/bin/zypper', 'name' : 'zypper' },
|
{ 'path' : '/usr/bin/zypper', 'name' : 'zypper' },
|
||||||
{ 'path' : '/usr/bin/pacman', 'name' : 'pacman' },
|
{ 'path' : '/usr/bin/pacman', 'name' : 'pacman' },
|
||||||
{ 'path' : '/opt/local/bin/pkgin', 'name' : 'pkgin' } ]
|
{ 'path' : '/opt/local/bin/pkgin', 'name' : 'pkgin' } ]
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -133,10 +133,11 @@ class Facts(object):
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
if self.facts['distribution'] == 'Fedora':
|
if self.facts['distribution'] == 'Fedora':
|
||||||
pass
|
pass
|
||||||
elif name == 'Amazon':
|
elif name == 'OtherLinux':
|
||||||
self.facts['distribution'] = 'Amazon'
|
|
||||||
data = get_file_content(path)
|
data = get_file_content(path)
|
||||||
self.facts['distribution_version'] = data.split()[-1]
|
if 'Amazon' in data:
|
||||||
|
self.facts['distribution'] = 'Amazon'
|
||||||
|
self.facts['distribution_version'] = data.split()[-1]
|
||||||
elif name == 'RedHat':
|
elif name == 'RedHat':
|
||||||
data = get_file_content(path)
|
data = get_file_content(path)
|
||||||
if 'Red Hat' in data:
|
if 'Red Hat' in data:
|
||||||
|
@ -682,7 +683,7 @@ class LinuxNetwork(Network):
|
||||||
continue
|
continue
|
||||||
rc, out, err = module.run_command(command[v])
|
rc, out, err = module.run_command(command[v])
|
||||||
if not out:
|
if not out:
|
||||||
# v6 routing may result in
|
# v6 routing may result in
|
||||||
# RTNETLINK answers: Invalid argument
|
# RTNETLINK answers: Invalid argument
|
||||||
continue
|
continue
|
||||||
words = out.split('\n')[0].split()
|
words = out.split('\n')[0].split()
|
||||||
|
@ -843,7 +844,7 @@ class LinuxVirtual(Virtual):
|
||||||
except IOError:
|
except IOError:
|
||||||
pass
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.path.exists('/proc/vz'):
|
if os.path.exists('/proc/vz'):
|
||||||
self.facts['virtualization_type'] = 'openvz'
|
self.facts['virtualization_type'] = 'openvz'
|
||||||
if os.path.exists('/proc/bc'):
|
if os.path.exists('/proc/bc'):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue