File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed
Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
88## [ Unreleased]
99
10+ ### Fixed
11+
12+ - Use collection version in User-Agent header instead of Ansible version.
13+
1014## [ 0.8.0] - 2025-08-18
1115
1216### Added
Original file line number Diff line number Diff line change 128128from ansible .errors import AnsibleError
129129from ansible .module_utils ._text import to_native
130130from ansible .plugins .inventory import BaseInventoryPlugin , Constructable
131- from ansible .release import __version__
132131from ansible .utils .display import Display
133132
133+ from ..version import collection_version
134+
134135display = Display ()
135136
136137try :
@@ -182,7 +183,8 @@ def _initialize_upcloud_client(self):
182183 'Update upcloud-api to version 2.8.0 or later.'
183184 ) from None
184185
185- self .client .api .user_agent = f"upcloud-ansible-inventory/{ __version__ } "
186+ version = collection_version () or "dev"
187+ self .client .api .user_agent = f"upcloud-ansible-inventory/{ version } "
186188
187189 api_root_env = "UPCLOUD_API_ROOT"
188190 if os .getenv (api_root_env ):
Original file line number Diff line number Diff line change 1+ import json
2+ import os
3+ import yaml
4+
5+
6+ def collection_version ():
7+ '''Read collection version from MANIFEST.json or galaxy.yml'''
8+ plugins_dir = os .path .dirname (os .path .abspath (__file__ ))
9+
10+ try :
11+ with open (os .path .join (plugins_dir , '../MANIFEST.json' )) as f :
12+ data = json .load (f )
13+ return data .get ('collection_info' , {}).get ('version' )
14+ except (FileNotFoundError , json .JSONDecodeError ):
15+ pass
16+
17+ try :
18+ with open (os .path .join (plugins_dir , '../galaxy.yml' )) as f :
19+ data = yaml .safe_load (f )
20+ return data .get ('version' )
21+ except (FileNotFoundError , yaml .YAMLError ):
22+ pass
23+
24+ return None
You can’t perform that action at this time.
0 commit comments