Skip to content

Commit

Permalink
Merge pull request #39 from theko2fi/master
Browse files Browse the repository at this point in the history
Improve connections listing
  • Loading branch information
pescobar authored Jun 8, 2023
2 parents 73f0e78 + 99f91a2 commit 010dcd4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion devel-utils/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
init-guac-db:
image: guacamole/guacamole:latest
user: root
command: ["/bin/sh", "-c", "test -e /init/initdb.sql && echo 'init file already exists' || /opt/guacamole/bin/initdb.sh --postgres > /init/initdb.sql" ]
command: ["/bin/sh", "-c", "test -e /init/initdb.sql && echo 'init file already exists' || /opt/guacamole/bin/initdb.sh --postgresql > /init/initdb.sql" ]
volumes:
- dbinit:/init

Expand Down
4 changes: 2 additions & 2 deletions plugins/inventory/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# scicore.guacamole.guacamole_inventory – Apache Guacamole dynamic inventory plugin

Wait would you say about getting all your connections details from Apache Guacamole and parsing them to ansible as inventory ? It would be amazing, right ?
What would you say about getting all your connections details from Apache Guacamole and passing them to Ansible as inventory ? It would be amazing, right ?

Guess what, You are in the right place. It's all about this plugin.

Expand All @@ -15,7 +15,7 @@ Guess what, You are in the right place. It's all about this plugin.
## Synopsis

- Get connection details from Apache Guacamole API and parse them to ansible as inventory.
- Get connection details from Apache Guacamole API and pass them to ansible as inventory.
- Uses an YAML configuration file ending with either `guacamole.yml` or `guacamole.yaml` to set parameter values.

## Requirements
Expand Down
16 changes: 9 additions & 7 deletions plugins/module_utils/guacamole.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ def guacamole_get_connections(base_url, validate_certs, datasource, group, auth_


all_connections = []
if 'childConnections' in connections_group:
all_connections = connections_group['childConnections']

if 'childConnectionGroups' in connections_group:
for group in connections_group['childConnectionGroups']:
if 'childConnections' in group:
all_connections = all_connections + group['childConnections']
def fetch_child_connections(a_connections_group, depth=0):
for connection in a_connections_group:
all_connections.extend(connection.get('childConnections',[]))
if connection.get('childConnectionGroups') is not None:
fetch_child_connections(connection.get('childConnectionGroups'), depth = depth + 1)
if depth == 0:
return

fetch_child_connections([connections_group])

return all_connections

Expand Down

0 comments on commit 010dcd4

Please sign in to comment.