Skip to content
Snippets Groups Projects
Commit f3114b7e authored by Carolina Fernandez's avatar Carolina Fernandez
Browse files

Merge branch 'develop' into 'feature/doc-update'

# Conflicts:
#   README.md
parents c3a44627 d3b9edfb
No related branches found
No related tags found
1 merge request!2feature/doc-update: add more details in README
Pipeline #85536 passed
......@@ -34,6 +34,8 @@ export host_vars_dir=/path/to/base/hostvars/dir
export hosts_file_dir=/path/to/base/hosts/dir
## Full path where this tool will save the WFO variables
export vars_file_name=wfo_vars.yaml
## Token provided by each GSO instance admin (varies per environment)
export gso_api_key=<fill_with_gso_token>
# Execution of the command to generate the Ansible inventory files
ansible_inventory_generator
......@@ -43,7 +45,24 @@ Ansible inventory files will be available under the path stated under `hosts_fil
## Troubleshooting
### 403 error
### Issues when installing the PIP package
When experiencing an error like the following, switch to the user that has permissions over `/usr/local/bin`:
```bash
PermissionError: [Errno 13] Permission denied: '/usr/local/bin/ansible_inventory_generator'
```
If facing an error like the following, it may suggest a compatibility issue (maybe with the version of setuptools, wheels or pip):
```bash
AttributeError: install_layout. Did you mean: 'install_platlib'?
```
To try to address it, run the following:
```bash
pip install -U pip setuptools wheel
```
### 403 error when running the `ansible_inventory_generator` command
This tool cannot reach the WFO API because it is authenticated.
Correct it by redeploying WFO by first running `export OAUTH2_ACTIVE=false` and then re-running WFO.
Alternatively, change `export api_url` to an authenticated instance of GSO.
\ No newline at end of file
......@@ -100,7 +100,9 @@ def safe_write(temp_dir: Path, old_vars_dir: Path, old_hosts_file: Path) -> Gene
def generate_inventory_from_api() -> None:
settings = load_settings()
"""Generate Ansible inventory from API."""
response = requests.get(settings.api_url, timeout=API_TIMEOUT_SEC)
response = requests.get(
settings.api_url, timeout=API_TIMEOUT_SEC, headers={"Authorization": f"Bearer {settings.gso_api_key}"}
)
response.raise_for_status()
try:
router_subscriptions = response.json()
......
......@@ -6,6 +6,7 @@ class Settings(BaseSettings):
host_vars_dir: str
vars_file_name: str
hosts_file_dir: str
gso_api_key: str
class Config:
env_file = "../.env"
......
......@@ -2,3 +2,4 @@ api_url=http://127.0.0.1:8080/api/v1/subscriptions/routers
host_vars_dir=/path/to/base/hostvars/dir
vars_file_name=wfo_vars.yaml
hosts_file_dir=/path/to/base/hosts/dir
gso_api_key=askjdhaskhdaksjhdkajshdkashd
......@@ -4,7 +4,7 @@ setup(
name="ansible_inventory_generator",
version="0.1",
author="GEANT",
author_email="swd@geant.org",
author_email="gap@geant.org",
description="Ansible inventory generator for WFO",
url="https://gitlab.software.geant.org/goat/gap/ansible_inventory_generator",
packages=find_packages(),
......
......@@ -157,6 +157,7 @@ def setup_test(tmp_dir, mocked_subscription_api_data):
host_vars_dir=str(tmp_dir),
vars_file_name="wfo_vars.yaml",
hosts_file_dir=str(tmp_dir),
gso_api_key="random_gso_api_key",
)
mock_get.return_value.json.return_value = mocked_subscription_api_data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment