PEP8 fixes: Ansible system module and playbook base.py (#32322)

* Ansible files module sanity pep8 fixes

* Ansible system module and playbook base.py

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Undo empty lines not required by sanity checks

* Various changes

* Various changes

* Various changes

* Various changes

* Undo blank lines not required by sanity checks

* Various changes

* Various changes

* Various changes

* Various changes

* Various changes

* Undo blank line changes not required by sanity checks

* Various changes

* Various changes

* Various changes

* Various changes

* Various changes

* Missing piece after merge

* Blank lines

* Blank line

* Line too long

* Fix typo

* Unnecessary quotes

* Fix example error
This commit is contained in:
Yadnyawalkya Tale
2017-11-07 08:38:59 +00:00
committed by Dag Wieers
parent a5da2e44a1
commit a2d34e914e
31 changed files with 878 additions and 1004 deletions

View File

@@ -1,56 +1,55 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2012, Stephen Fromm <sfromm@gmail.com>
# Copyright: (c) 2012, Stephen Fromm <sfromm@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'core'}
DOCUMENTATION = '''
---
module: group
author: "Stephen Fromm (@sfromm)"
author:
- Stephen Fromm (@sfromm)
version_added: "0.0.2"
short_description: Add or remove groups
requirements: [ groupadd, groupdel, groupmod ]
requirements:
- groupadd
- groupdel
- groupmod
description:
- Manage presence of groups on a host.
- For Windows targets, use the M(win_group) module instead.
options:
name:
required: true
description:
- Name of the group to manage.
required: true
gid:
required: false
description:
- Optional I(GID) to set for the group.
state:
required: false
default: "present"
choices: [ present, absent ]
description:
- Whether the group should be present or not on the remote host.
choices: [ absent, present ]
default: present
system:
required: false
default: "no"
choices: [ "yes", "no" ]
description:
- If I(yes), indicates that the group created is a system group.
type: bool
default: 'no'
notes:
- For Windows targets, use the M(win_group) module instead.
'''
EXAMPLES = '''
# Example group command from Ansible Playbooks
- group:
- name: Ensure group "somegroup" exists
group:
name: somegroup
state: present
'''
@@ -81,11 +80,11 @@ class Group(object):
return load_platform_subclass(Group, args, kwargs)
def __init__(self, module):
self.module = module
self.state = module.params['state']
self.name = module.params['name']
self.gid = module.params['gid']
self.system = module.params['system']
self.module = module
self.state = module.params['state']
self.name = module.params['name']
self.gid = module.params['gid']
self.system = module.params['system']
def execute_command(self, cmd):
return self.module.run_command(cmd)
@@ -136,6 +135,7 @@ class Group(object):
return False
return info
# ===========================================
class SunOS(Group):
@@ -205,6 +205,7 @@ class AIX(Group):
cmd.append(self.name)
return self.execute_command(cmd)
# ===========================================
class FreeBsdGroup(Group):
@@ -246,10 +247,9 @@ class FreeBsdGroup(Group):
return self.execute_command(cmd)
return (None, '', '')
# ===========================================
class DarwinGroup(Group):
"""
This is a Mac OS X Darwin Group manipulation class.
@@ -267,22 +267,22 @@ class DarwinGroup(Group):
def group_add(self, **kwargs):
cmd = [self.module.get_bin_path('dseditgroup', True)]
cmd += [ '-o', 'create' ]
cmd += ['-o', 'create']
if self.gid is not None:
cmd += [ '-i', self.gid ]
cmd += ['-i', self.gid]
elif 'system' in kwargs and kwargs['system'] is True:
gid = self.get_lowest_available_system_gid()
if gid is not False:
self.gid = str(gid)
cmd += [ '-i', self.gid ]
cmd += [ '-L', self.name ]
cmd += ['-i', self.gid]
cmd += ['-L', self.name]
(rc, out, err) = self.execute_command(cmd)
return (rc, out, err)
def group_del(self):
cmd = [self.module.get_bin_path('dseditgroup', True)]
cmd += [ '-o', 'delete' ]
cmd += [ '-L', self.name ]
cmd += ['-o', 'delete']
cmd += ['-L', self.name]
(rc, out, err) = self.execute_command(cmd)
return (rc, out, err)
@@ -290,10 +290,10 @@ class DarwinGroup(Group):
info = self.group_info()
if self.gid is not None and int(self.gid) != info[2]:
cmd = [self.module.get_bin_path('dseditgroup', True)]
cmd += [ '-o', 'edit' ]
cmd += ['-o', 'edit']
if gid is not None:
cmd += [ '-i', gid ]
cmd += [ '-L', self.name ]
cmd += ['-i', gid]
cmd += ['-L', self.name]
(rc, out, err) = self.execute_command(cmd)
return (rc, out, err)
return (None, '', '')
@@ -302,7 +302,7 @@ class DarwinGroup(Group):
# check for lowest available system gid (< 500)
try:
cmd = [self.module.get_bin_path('dscl', True)]
cmd += [ '/Local/Default', '-list', '/Groups', 'PrimaryGroupID']
cmd += ['/Local/Default', '-list', '/Groups', 'PrimaryGroupID']
(rc, out, err) = self.execute_command(cmd)
lines = out.splitlines()
highest = 0
@@ -318,6 +318,7 @@ class DarwinGroup(Group):
except:
return False
class OpenBsdGroup(Group):
"""
This is a OpenBSD Group manipulation class.
@@ -357,6 +358,7 @@ class OpenBsdGroup(Group):
cmd.append(self.name)
return self.execute_command(cmd)
# ===========================================
class NetBsdGroup(Group):
@@ -398,17 +400,18 @@ class NetBsdGroup(Group):
cmd.append(self.name)
return self.execute_command(cmd)
# ===========================================
def main():
module = AnsibleModule(
argument_spec = dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(required=True, type='str'),
gid=dict(default=None, type='str'),
system=dict(default=False, type='bool'),
argument_spec=dict(
state=dict(type='str', default='present', choices=['absent', 'present']),
name=dict(type='str', required=True),
gid=dict(type='str'),
system=dict(type='bool', default=False),
),
supports_check_mode=True
supports_check_mode=True,
)
group = Group(module)