diff options
| author | Egor Tensin <egor@tensin.name> | 2026-08-06 13:07:27 +0200 |
|---|---|---|
| committer | Egor Tensin <egor@tensin.name> | 2026-08-06 13:08:45 +0200 |
| commit | d7c131e370306aff43ebbfe682df7ba64302d9f1 (patch) | |
| tree | 8581994225110a24d7faceb43ae4d06b0ed1cfeb /plugins/action | |
| parent | Merge pull request #2 from egor-tensin/dependabot/github_actions/actions/setu... (diff) | |
| download | infra-ansible-d7c131e370306aff43ebbfe682df7ba64302d9f1.tar.gz infra-ansible-d7c131e370306aff43ebbfe682df7ba64302d9f1.zip | |
reformat Python code with default Black settings
Diffstat (limited to 'plugins/action')
| -rwxr-xr-x | plugins/action/apt_wrapper.py | 14 | ||||
| -rwxr-xr-x | plugins/action/etckeeper_commit.py | 18 | ||||
| -rwxr-xr-x | plugins/action/parse_json_file.py | 8 | ||||
| -rwxr-xr-x | plugins/action/read_file.py | 6 | ||||
| -rwxr-xr-x | plugins/action/safe_git.py | 30 |
5 files changed, 38 insertions, 38 deletions
diff --git a/plugins/action/apt_wrapper.py b/plugins/action/apt_wrapper.py index 804454b..b524080 100755 --- a/plugins/action/apt_wrapper.py +++ b/plugins/action/apt_wrapper.py @@ -5,30 +5,30 @@ import re from ansible.plugins.action import ActionBase from ansible_collections.tensin.infra.plugins.module_utils import file -LOG_PATH = '/var/log/dpkg.log' +LOG_PATH = "/var/log/dpkg.log" class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): super().run(tmp, task_vars) - before = self._parse_dpkg_log(task_vars, default='') + before = self._parse_dpkg_log(task_vars, default="") apt_result = self._execute_module( - module_name='ansible.builtin.apt', - module_args=self._task.args.get('apt_args', {}), + module_name="ansible.builtin.apt", + module_args=self._task.args.get("apt_args", {}), task_vars=task_vars, ) after = self._parse_dpkg_log(task_vars) - apt_result['packages'] = after[len(before) :] + apt_result["packages"] = after[len(before) :] return apt_result def _parse_dpkg_log(self, task_vars, default=None): contents = file.read_file(self, LOG_PATH, task_vars, default=default) lines = contents.splitlines() - regex = re.compile(' install | upgrade | remove | purge ') + regex = re.compile(" install | upgrade | remove | purge ") lines = [line for line in lines if regex.search(line)] - lines = [' '.join(line.split(' ')[2:]) for line in lines] + lines = [" ".join(line.split(" ")[2:]) for line in lines] return lines diff --git a/plugins/action/etckeeper_commit.py b/plugins/action/etckeeper_commit.py index 06c7be0..d4c4519 100755 --- a/plugins/action/etckeeper_commit.py +++ b/plugins/action/etckeeper_commit.py @@ -11,16 +11,16 @@ class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): result = super().run(tmp, task_vars) - msg = self._task.args['msg'] - allowlist = self._task.args.get('allowlist', []) + msg = self._task.args["msg"] + allowlist = self._task.args.get("allowlist", []) allowlist = [re.compile(pattern) for pattern in allowlist] - skip_no_changes = self._task.args.get('skip_no_changes', False) + skip_no_changes = self._task.args.get("skip_no_changes", False) - dirty_files = git.get_dirty_file_list(self, '/etc', task_vars) + dirty_files = git.get_dirty_file_list(self, "/etc", task_vars) if not dirty_files: if skip_no_changes: return result - raise AnsibleActionFail('Nothing to commit') + raise AnsibleActionFail("Nothing to commit") if allowlist: unexpected = [ @@ -37,12 +37,12 @@ class ActionModule(ActionBase): def _commit(self, msg, task_vars): cmd_result = self._execute_module( - module_name='ansible.builtin.command', + module_name="ansible.builtin.command", module_args=dict( - argv=['etckeeper', 'commit', msg], + argv=["etckeeper", "commit", msg], ), task_vars=task_vars, ) - if cmd_result.get('failed'): - raise AnsibleActionFail('etckeeper commit failed', result=cmd_result) + if cmd_result.get("failed"): + raise AnsibleActionFail("etckeeper commit failed", result=cmd_result) return cmd_result diff --git a/plugins/action/parse_json_file.py b/plugins/action/parse_json_file.py index d9c864a..fe776a8 100755 --- a/plugins/action/parse_json_file.py +++ b/plugins/action/parse_json_file.py @@ -11,8 +11,8 @@ class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): result = super().run(tmp, task_vars) - path = self._task.args['path'] - default = self._task.args.get('default') + path = self._task.args["path"] + default = self._task.args.get("default") if default is not None: default = json.dumps(default) @@ -21,7 +21,7 @@ class ActionModule(ActionBase): try: content = json.loads(content) except json.JSONDecodeError as e: - raise AnsibleActionFail(f'Failed to parse JSON at {path}') from e + raise AnsibleActionFail(f"Failed to parse JSON at {path}") from e - result['content'] = content + result["content"] = content return result diff --git a/plugins/action/read_file.py b/plugins/action/read_file.py index 3370846..ec43e1e 100755 --- a/plugins/action/read_file.py +++ b/plugins/action/read_file.py @@ -8,8 +8,8 @@ class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): result = super().run(tmp, task_vars) - path = self._task.args['path'] - default = self._task.args.get('default') + path = self._task.args["path"] + default = self._task.args.get("default") - result['content'] = file.read_file(self, path, task_vars, default=default) + result["content"] = file.read_file(self, path, task_vars, default=default) return result diff --git a/plugins/action/safe_git.py b/plugins/action/safe_git.py index 8389169..8d4504b 100755 --- a/plugins/action/safe_git.py +++ b/plugins/action/safe_git.py @@ -9,25 +9,25 @@ class ActionModule(ActionBase): def run(self, tmp=None, task_vars=None): result = super().run(tmp, task_vars) - repo = self._task.args['repo'] - dest = self._task.args['dest'] - accept_hostkey = self._task.args.get('accept_hostkey', False) - remote = self._task.args.get('remote', 'origin') - version = self._task.args['version'] + repo = self._task.args["repo"] + dest = self._task.args["dest"] + accept_hostkey = self._task.args.get("accept_hostkey", False) + remote = self._task.args.get("remote", "origin") + version = self._task.args["version"] builtin_args = { - 'repo': repo, - 'dest': dest, - 'accept_hostkey': accept_hostkey, - 'remote': remote, - 'version': version, + "repo": repo, + "dest": dest, + "accept_hostkey": accept_hostkey, + "remote": remote, + "version": version, } if not file.does_dir_exist(self, dest, task_vars): # If the destination directory doesn't exist, delegate to the # builtin module. return self._execute_module( - module_name='ansible.builtin.git', + module_name="ansible.builtin.git", module_args=builtin_args, task_vars=task_vars, ) @@ -35,7 +35,7 @@ class ActionModule(ActionBase): # ansible.builtin.git would just remove everything, fuck that. if not git.is_work_tree(self, dest, task_vars): raise AnsibleActionFail( - f'Destination {dest} exists but is not a repository' + f"Destination {dest} exists but is not a repository" ) # Again, ansible.builtin.git would just remove everything, fuck that. @@ -49,7 +49,7 @@ class ActionModule(ActionBase): # `false`, but I don't want to depend on default values. dirty_files = git.get_dirty_file_list(self, dest, task_vars) if dirty_files: - raise AnsibleActionFail(f'There are local changes in {dest}') + raise AnsibleActionFail(f"There are local changes in {dest}") # Fetch the remote. git.update_remote(self, dest, remote, task_vars, accept_hostkey=accept_hostkey) @@ -59,12 +59,12 @@ class ActionModule(ActionBase): is_ancestor = git.is_ancestor(self, dest, remote, version, task_vars) if not is_ancestor: raise AnsibleActionFail( - f'HEAD in {dest} is not an ancestor of {remote}/{version}' + f"HEAD in {dest} is not an ancestor of {remote}/{version}" ) # Finally, everything looks good, delegate to the builtin module. return self._execute_module( - module_name='ansible.builtin.git', + module_name="ansible.builtin.git", module_args=builtin_args, task_vars=task_vars, ) |
