diff --git a/changelogs/fragments/httpapi_make_ansible_network_os_optional_param.yaml b/changelogs/fragments/httpapi_make_ansible_network_os_optional_param.yaml new file mode 100644 index 000000000..b76996d93 --- /dev/null +++ b/changelogs/fragments/httpapi_make_ansible_network_os_optional_param.yaml @@ -0,0 +1,3 @@ +--- +minor_changes: + - Make ansible_network_os as optional param for httpapi connection plugin. diff --git a/plugins/connection/httpapi.py b/plugins/connection/httpapi.py index 41859857f..37285fd78 100644 --- a/plugins/connection/httpapi.py +++ b/plugins/connection/httpapi.py @@ -142,6 +142,13 @@ - name: ANSIBLE_BECOME_METHOD vars: - name: ansible_become_method + platform_type: + description: + - Set type of platform. + env: + - name: ANSIBLE_PLATFORM_TYPE + vars: + - name: ansible_platform_type """ from io import BytesIO @@ -169,10 +176,14 @@ def __init__(self, play_context, new_stdin, *args, **kwargs): ) self._auth = None - if self._network_os: + self.load_platform_plugins(self._network_os) + + def load_platform_plugins(self, platform_type=None): + platform_type = platform_type or self.get_option("platform_type") - self.httpapi = httpapi_loader.get(self._network_os, self) + if platform_type: + self.httpapi = httpapi_loader.get(platform_type, self) if self.httpapi: self._sub_plugin = { "type": "httpapi", @@ -181,25 +192,25 @@ def __init__(self, play_context, new_stdin, *args, **kwargs): } self.queue_message( "vvvv", - "loaded API plugin %s from path %s for network_os %s" + "loaded API plugin %s from path %s for platform type %s" % ( self.httpapi._load_name, self.httpapi._original_path, - self._network_os, + platform_type, ), ) else: raise AnsibleConnectionFailure( - "unable to load API plugin for network_os %s" - % self._network_os + "unable to load API plugin for platform type %s" + % platform_type ) else: raise AnsibleConnectionFailure( - "Unable to automatically determine host network os. Please " - "manually configure ansible_network_os value for this host" + "Unable to automatically determine host platform type. Please " + "manually configure platform_type value for this host" ) - self.queue_message("log", "network_os is set to %s" % self._network_os) + self.queue_message("log", "platform_type is set to %s" % platform_type) @property def _url(self):