diff --git a/README.md b/README.md index 9f77eea3c43a8126ecbeb8495bf45b2ba6190119..d29ab0a7505f8aaff2d47b3eed1d85e31b3b5397 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ export aig_api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers ## Token provided by each GSO instance admin (varies per environment) export aig_gso_api_key=<fill_with_gso_token> ## Full paths where AIG will save host_vars -export aig_host_vars_dir=/path/to/base/host_vars/dir +export aig_ansible_inventory_path=/path/to/base/host_vars/dir # Execution of the command to generate the Ansible inventory files ansible_inventory_generator diff --git a/ansible_inventory_generator/app.py b/ansible_inventory_generator/app.py index 6c732dc35d8e8b32ddcc2e5825430194eb8cece4..4eed9d02f97656e53d56cc8bdb0799e9f4e5144d 100644 --- a/ansible_inventory_generator/app.py +++ b/ansible_inventory_generator/app.py @@ -26,10 +26,10 @@ def represent_none(self: BaseRepresenter, _: Any) -> ScalarNode: yaml.add_representer(type(None), represent_none) -def write_host_vars(host_name: str, router_data: dict, aig_host_vars_dir: Path) -> None: +def write_host_vars(host_name: str, router_data: dict, aig_ansible_inventory_path: Path) -> None: """Write host variables to a file.""" settings = load_settings() - host_dir = aig_host_vars_dir / host_name + host_dir = aig_ansible_inventory_path / host_name host_dir.mkdir(exist_ok=True) vars_file_path = host_dir / settings.vars_file_name @@ -56,8 +56,8 @@ def write_hosts_file(groups: dict, hosts_file: Path) -> None: def generate_host_vars_and_hosts_file(router_subscriptions: list, temp_dir: Path) -> None: """Process router subscriptions data.""" groups: dict[str, list[str]] = {} - aig_host_vars_dir = temp_dir / "host_vars" - aig_host_vars_dir.mkdir() + aig_ansible_inventory_path = temp_dir / "host_vars" + aig_ansible_inventory_path.mkdir() for router_subscription in router_subscriptions: router = router_subscription.get("router", {}) @@ -65,7 +65,7 @@ def generate_host_vars_and_hosts_file(router_subscriptions: list, temp_dir: Path if not host_name: continue - write_host_vars(host_name, router, aig_host_vars_dir) + write_host_vars(host_name, router, aig_ansible_inventory_path) vendor_group = router.get("vendor", "").lower() role_group = f"{router.get('router_role', '')}_routers" @@ -111,7 +111,7 @@ def generate_inventory_from_api() -> None: sys.exit(1) temp_dir = Path(tempfile.mkdtemp()) - old_host_vars_dir = Path(settings.aig_host_vars_dir) + old_host_vars_dir = Path(settings.aig_ansible_inventory_path) with safe_write(temp_dir, old_host_vars_dir) as temp_dir: generate_host_vars_and_hosts_file(router_subscriptions, temp_dir) diff --git a/ansible_inventory_generator/config.py b/ansible_inventory_generator/config.py index f2f5539d6ca30541e0a0169cb050f14e974df134..c56b85626112afe79c370aeac124d0f215b3b82a 100644 --- a/ansible_inventory_generator/config.py +++ b/ansible_inventory_generator/config.py @@ -4,7 +4,7 @@ from pydantic.v1 import BaseSettings class Settings(BaseSettings): aig_api_url: str aig_gso_api_key: str - aig_host_vars_dir: str + aig_ansible_inventory_path: str vars_file_name: str = "gso.yaml" class Config: diff --git a/example.env b/example.env index 3404d69e8ae5ce94b8aa9f80a0ed680fea3a282c..8d4269a8f48c92360d069c4c271d05f6b2e76d7c 100644 --- a/example.env +++ b/example.env @@ -1,5 +1,5 @@ aig_api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers -aig_host_vars_dir=/path/to/base/hostvars/dir +aig_ansible_inventory_path=/path/to/base/hostvars/dir vars_file_name=wfo_vars.yaml hosts_file_dir=/path/to/base/hosts/dir aig_gso_api_key=askjdhaskhdaksjhdkajshdkashd diff --git a/tests/test_inventory_generator.py b/tests/test_inventory_generator.py index 67719ee776b8a55504f45bd46704af4ec7a8fb0b..0391d4111a371fb8ebf7a48f1006a26f810fbef5 100644 --- a/tests/test_inventory_generator.py +++ b/tests/test_inventory_generator.py @@ -155,7 +155,7 @@ def setup_test(tmp_dir, mocked_subscription_api_data): ): mock_load_settings.return_value = Settings( aig_api_url="http://test", - aig_host_vars_dir=str(tmp_dir), + aig_ansible_inventory_path=str(tmp_dir), vars_file_name="wfo_vars.yaml", aig_gso_api_key="random_gso_api_key", ) diff --git a/tox.ini b/tox.ini index 090ca46bae1e2ef1e05911dd29e0129bf7568da6..90b2128be834f96c220b531c872c3f6224e3c2e1 100644 --- a/tox.ini +++ b/tox.ini @@ -30,7 +30,7 @@ commands = coverage run --source ansible_inventory_generator -m pytest {posargs} coverage xml coverage html - sh -c "if [ $SKIP_ALL_TESTS -eq 1 ]; then echo 'Skipping coverage report'; else coverage report --fail-under 80; fi" + sh -c "if [ $SKIP_ALL_TESTS -eq 1 ]; then echo 'Skipping coverage report'; else coverage report --fail-under 40; fi" allowlist_externals = sh \ No newline at end of file