Skip to content

Commit

Permalink
Make setting ansible_network_os optional (#329)
Browse files Browse the repository at this point in the history
Make setting ansible_network_os optional

SUMMARY

Make setting ansible_network_os optional

Depends-on: ansible/ansible-zuul-jobs#1139
ISSUE TYPE


Feature Pull Request

COMPONENT NAME

httpapi
ADDITIONAL INFORMATION

Reviewed-by: Ganesh Nalawade <None>
Reviewed-by: Sumit Jaiswal <[email protected]>
Reviewed-by: Nathaniel Case <[email protected]>
Reviewed-by: None <None>
  • Loading branch information
justjais authored Oct 5, 2021
1 parent c0ba21a commit 71900b5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
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

0 comments on commit 71900b5

Please sign in to comment.