Skip to content

Commit

Permalink
load_config now resolves relativ paths
Browse files Browse the repository at this point in the history
  • Loading branch information
lfkdev committed Jun 29, 2024
1 parent c28261d commit 2ac25fd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
- name: set up python
uses: actions/setup-python@v5
with:
python-version: '3.8'
Expand All @@ -34,7 +34,7 @@ jobs:
echo "log_level: 'DEBUG'" >> config.yml
echo "playbook_whitelist:" >> config.yml
echo " - test_.+\.yml$" >> config.yml
- name: create test files/folders
- name: Create test files/folders
working-directory: ${{ github.workspace }}/src
run: |
mkdir -p test_playbooks test_job_storage
Expand All @@ -52,13 +52,13 @@ jobs:
debug:
msg: "This is a test playbook"
EOF
- name: show structure and files
- name: Show structure and files
working-directory: ${{ github.workspace }}/src
run: |
ls -R
cat config.yml
cat test_playbooks/test_playbook.yml
- name: run tests
- name: Run tests
run: |
python -m unittest discover src
Expand Down
12 changes: 10 additions & 2 deletions src/ansible_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ def load_config():
print(f"{datetime.now().isoformat()} - INFO - Loading configuration from {config_path}")
try:
with open(config_path, 'r') as f:
return yaml.safe_load(f)
config = yaml.safe_load(f)

# resolve relative paths
for key in ['playbook_dir', 'inventory_file', 'job_storage_dir']:
if key in config and not os.path.isabs(config[key]):
config[key] = os.path.abspath(os.path.join(current_dir, config[key]))
print(f"{datetime.now().isoformat()} - INFO - Resolved {key} to {config[key]}")

return config
except Exception as e:
print(f"{datetime.now().isoformat()} - ERROR - Failed to load configuration: {e} - is ANSIBLE_LINK_CONFIG_PATH set correctly?")
raise
raise

def validate_playbook(playbook):
playbook_path = Path(config['playbook_dir']) / playbook
Expand Down

0 comments on commit 2ac25fd

Please sign in to comment.