1
0
Fork 0
mirror of https://github.com/containers/ansible-podman-collections.git synced 2026-02-04 07:11:49 +00:00

Add suggestions

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
This commit is contained in:
Sagi Shnaidman 2025-08-13 12:34:46 +03:00
parent 33e9009040
commit e9453bbc82
3 changed files with 25 additions and 34 deletions

View file

@ -46,10 +46,10 @@ import json
import fnmatch
import shutil
import subprocess
import os
from ansible.errors import AnsibleParserError
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable
from ansible_collections.containers.podman.plugins.module_utils.inventory.utils import verify_inventory_file
class InventoryModule(BaseInventoryPlugin, Cacheable):
@ -58,19 +58,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
def verify_file(self, path: str) -> bool:
if not super(InventoryModule, self).verify_file(path):
return False
unused, ext = os.path.splitext(path)
if ext not in (".yml", ".yaml"):
return False
try:
with open(path, "r", encoding="utf-8") as f:
header = f.read(2048)
return (
(f"plugin: {self.NAME}\n" in header)
or (f"plugin: '{self.NAME}'" in header)
or (f'plugin: "{self.NAME}"' in header)
)
except Exception:
return False
return verify_inventory_file(self, path)
def parse(self, inventory, loader, path, cache=True):
super(InventoryModule, self).parse(inventory, loader, path)

View file

@ -90,12 +90,10 @@ import json
import fnmatch
import shutil
import subprocess
import os
from ansible.utils.display import Display
from typing import Dict, List
from ansible.errors import AnsibleParserError
from ansible.plugins.inventory import BaseInventoryPlugin, Cacheable
from ansible_collections.containers.podman.plugins.module_utils.inventory.utils import verify_inventory_file
class InventoryModule(BaseInventoryPlugin, Cacheable):
@ -103,24 +101,11 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
def __init__(self):
super(InventoryModule, self).__init__()
self.display = Display()
def verify_file(self, path: str) -> bool:
if not super(InventoryModule, self).verify_file(path):
return False
unused, ext = os.path.splitext(path)
if ext not in (".yml", ".yaml"):
return False
try:
with open(path, "r", encoding="utf-8") as f:
header = f.read(2048)
return (
(f"plugin: {self.NAME}\n" in header)
or (f"plugin: '{self.NAME}'" in header)
or (f'plugin: "{self.NAME}"' in header)
)
except Exception:
return False
return verify_inventory_file(self, path)
def parse(self, inventory, loader, path, cache=True):
super(InventoryModule, self).parse(inventory, loader, path)
@ -129,10 +114,10 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
executable = config.get("executable", "podman")
include_stopped = bool(config.get("include_stopped", False))
name_patterns = list(config.get("name_patterns", []) or [])
label_selectors: Dict[str, str] = dict(config.get("label_selectors", {}) or {})
label_selectors = dict(config.get("label_selectors", {}) or {})
connection_plugin = config.get("connection_plugin", "containers.podman.podman")
group_by_image = bool(config.get("group_by_image", True))
group_by_label: List[str] = list(config.get("group_by_label", []) or [])
group_by_label = list(config.get("group_by_label", []) or [])
verbose_output = bool(config.get("verbose_output", False))
strict = bool(config.get("strict", False))
keyed_groups = list(config.get("keyed_groups", []) or [])
@ -268,7 +253,7 @@ class InventoryModule(BaseInventoryPlugin, Cacheable):
# Resolve dotted key path against hostvars
value = None
cur = hostvars
for part in str(key_expr).split('.'):
for part in str(key_expr).split("."):
if isinstance(cur, dict) and part in cur:
cur = cur.get(part)
else:

View file

@ -0,0 +1,18 @@
import os
def verify_inventory_file(self, path: str) -> bool:
unused, ext = os.path.splitext(path)
if ext not in (".yml", ".yaml"):
return False
try:
with open(path, "r", encoding="utf-8") as f:
header = f.read(2048)
return (
(f"plugin: {self.NAME}\n" in header)
or (f"plugin: '{self.NAME}'" in header)
or (f'plugin: "{self.NAME}"' in header)
)
except Exception:
return False