Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make setting ansible_network_os optional #329

Merged
merged 7 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
minor_changes:
- Make ansible_network_os as optional param for httpapi connection plugin.
29 changes: 20 additions & 9 deletions plugins/connection/httpapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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):
Expand Down