mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-02-04 07:51:50 +00:00
Reformat everything.
This commit is contained in:
parent
3f2213791a
commit
340ff8586d
1008 changed files with 61301 additions and 58309 deletions
|
|
@ -54,34 +54,34 @@ from ansible_collections.community.general.plugins.module_utils.module_helper im
|
|||
|
||||
|
||||
class Blacklist(StateModuleHelper):
|
||||
output_params = ('name', 'state')
|
||||
output_params = ("name", "state")
|
||||
module = dict(
|
||||
argument_spec=dict(
|
||||
name=dict(type='str', required=True),
|
||||
state=dict(type='str', default='present', choices=['absent', 'present']),
|
||||
blacklist_file=dict(type='str', default='/etc/modprobe.d/blacklist-ansible.conf'),
|
||||
name=dict(type="str", required=True),
|
||||
state=dict(type="str", default="present", choices=["absent", "present"]),
|
||||
blacklist_file=dict(type="str", default="/etc/modprobe.d/blacklist-ansible.conf"),
|
||||
),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
def __init_module__(self):
|
||||
self.pattern = re.compile(rf'^blacklist\s+{re.escape(self.vars.name)}$')
|
||||
self.pattern = re.compile(rf"^blacklist\s+{re.escape(self.vars.name)}$")
|
||||
self.vars.filename = self.vars.blacklist_file
|
||||
self.vars.set('file_exists', os.path.exists(self.vars.filename), output=False, change=True)
|
||||
self.vars.set("file_exists", os.path.exists(self.vars.filename), output=False, change=True)
|
||||
if not self.vars.file_exists:
|
||||
with open(self.vars.filename, 'a'):
|
||||
with open(self.vars.filename, "a"):
|
||||
pass
|
||||
self.vars.file_exists = True
|
||||
self.vars.set('lines', [], change=True, diff=True)
|
||||
self.vars.set("lines", [], change=True, diff=True)
|
||||
else:
|
||||
with open(self.vars.filename) as fd:
|
||||
self.vars.set('lines', [x.rstrip() for x in fd.readlines()], change=True, diff=True)
|
||||
self.vars.set('is_blacklisted', self._is_module_blocked(), change=True)
|
||||
self.vars.set("lines", [x.rstrip() for x in fd.readlines()], change=True, diff=True)
|
||||
self.vars.set("is_blacklisted", self._is_module_blocked(), change=True)
|
||||
|
||||
def _is_module_blocked(self):
|
||||
for line in self.vars.lines:
|
||||
stripped = line.strip()
|
||||
if stripped.startswith('#'):
|
||||
if stripped.startswith("#"):
|
||||
continue
|
||||
if self.pattern.match(stripped):
|
||||
return True
|
||||
|
|
@ -97,7 +97,7 @@ class Blacklist(StateModuleHelper):
|
|||
if self.vars.is_blacklisted:
|
||||
return
|
||||
self.vars.is_blacklisted = True
|
||||
self.vars.lines = self.vars.lines + [f'blacklist {self.vars.name}']
|
||||
self.vars.lines = self.vars.lines + [f"blacklist {self.vars.name}"]
|
||||
|
||||
def __quit_module__(self):
|
||||
if self.has_changed() and not self.module.check_mode:
|
||||
|
|
@ -111,5 +111,5 @@ def main():
|
|||
Blacklist.execute()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue