Compare commits
8 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
90725d8998 | |
|
|
a221973f1e | |
|
|
38f3f4c7f4 | |
|
|
4b829fa9d1 | |
|
|
895904251f | |
|
|
6243672014 | |
|
|
7bfce168a3 | |
|
|
b5c798ea0e |
|
|
@ -0,0 +1,2 @@
|
|||
# These are supported funding model platforms
|
||||
open_collective: dominion-solutions-foss/projects/ansible-netbird
|
||||
|
|
@ -43,7 +43,7 @@ body:
|
|||
id: ansible-version
|
||||
attributes:
|
||||
label: Ansible Version
|
||||
description: What version of Laravel are you running? Please be as specific as possible
|
||||
description: What version of Ansible Core are you running? Please be as specific as possible
|
||||
placeholder: 2.16.4
|
||||
validations:
|
||||
required: true
|
||||
|
|
@ -57,6 +57,7 @@ body:
|
|||
- macOS
|
||||
- Windows
|
||||
- Linux
|
||||
- BSD
|
||||
- type: textarea
|
||||
id: notes
|
||||
attributes:
|
||||
|
|
|
|||
41
CHANGELOG.md
41
CHANGELOG.md
|
|
@ -2,6 +2,47 @@
|
|||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## Bug Fixes - Parameters - 2024-04-03
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
Thanks to @ipsecguy for pointing out that there was an issue with the compose variables.
|
||||
|
||||
- #28 - The compose parameter is updated to accept a `dict()` now.
|
||||
- The documentation has been improved as well.
|
||||
- Some small issues around creating bugs / questions have been resolved.
|
||||
|
||||
### What's Changed
|
||||
|
||||
* Update README.md by @spam-n-eggs in https://github.com/dominion-solutions/ansible-netbird/pull/26
|
||||
* Fixes #28 - Tested with a separate inventory. by @spam-n-eggs in https://github.com/dominion-solutions/ansible-netbird/pull/29
|
||||
|
||||
**Full Changelog**: https://github.com/dominion-solutions/ansible-netbird/compare/0.1.6...0.2.0
|
||||
|
||||
## Fixed an accidental bug in the last release - 2024-03-11
|
||||
|
||||
Bug was accidentally released in the last release. Fixed.
|
||||
|
||||
### What's Changed
|
||||
|
||||
* Mjh/fix issues with message by @spam-n-eggs in https://github.com/dominion-solutions/ansible-netbird/pull/24
|
||||
|
||||
**Full Changelog**: https://github.com/dominion-solutions/ansible-netbird/compare/0.1.5...0.1.6
|
||||
|
||||
## Small Bugfixes - 2024-03-11
|
||||
|
||||
Minor fixes including:
|
||||
|
||||
- #14 Error on bad credentials.
|
||||
- #22 Wrapped bad urls in an AnsibleError
|
||||
- #20 The issue templates were bad.
|
||||
|
||||
### What's Changed
|
||||
|
||||
* Mjh/14/error out on bad credentials by @spam-n-eggs in https://github.com/dominion-solutions/ansible-netbird/pull/23
|
||||
|
||||
**Full Changelog**: https://github.com/dominion-solutions/ansible-netbird/compare/0.1.4...0.1.5
|
||||
|
||||
## Documentation updates - 2024-03-01
|
||||
|
||||
Closes #16
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ strict: No
|
|||
---
|
||||
plugin: dominion_solutions.netbird.netbird
|
||||
api_key: nbp_this_is_a_fake_api_key
|
||||
api_url: https://netbird.example.com/api/v1
|
||||
api_url: https://netbird.example.com/api/
|
||||
netbird_connected: True
|
||||
```
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ This example gets all peers in the _All_ group and builds the additional _connec
|
|||
---
|
||||
plugin: dominion_solutions.netbird.netbird
|
||||
api_key: nbp_this_is_a_fake_api_key
|
||||
api_url: https://netbird.example.com/api/v1
|
||||
api_url: https://netbird.example.com/api/
|
||||
netbird_connected: False
|
||||
leading_separator: No
|
||||
netbird_groups:
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace: dominion_solutions
|
|||
name: netbird
|
||||
|
||||
# The version of the collection. Must be compatible with semantic versioning
|
||||
version: 0.1.5
|
||||
version: 0.2.0
|
||||
|
||||
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
|
||||
readme: README.md
|
||||
|
|
|
|||
|
|
@ -59,9 +59,8 @@ options:
|
|||
description: Whether or not to fail if a group or variable is not found.
|
||||
compose:
|
||||
description: compose variables for Ansible based on jinja2 expression and inventory vars
|
||||
default: False
|
||||
required: False
|
||||
type: boolean
|
||||
type: dict
|
||||
keyed_groups:
|
||||
description: create groups for plugins based on variable values and add the corresponding hosts to it
|
||||
type: list
|
||||
|
|
@ -93,7 +92,6 @@ from ansible.utils.display import Display
|
|||
|
||||
# Specific for the NetbirdAPI Class
|
||||
import json
|
||||
import re
|
||||
|
||||
try:
|
||||
import requests
|
||||
|
|
@ -151,8 +149,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
"""Get the inventory from the Netbird API"""
|
||||
try:
|
||||
self.peers = self.client.ListPeers()
|
||||
except Exception as e:
|
||||
raise AnsibleError(f"Could not retrieve the Netbird inventory: {e}")
|
||||
except Exception:
|
||||
raise AnsibleError("Could not retrieve the Netbird inventory. Check the API Key and URL.")
|
||||
|
||||
def _filter_by_config(self):
|
||||
"""Filter peers by user specified configuration."""
|
||||
|
|
@ -290,11 +288,8 @@ class NetbirdApi:
|
|||
}
|
||||
peers = []
|
||||
response = requests.request("GET", url, headers=headers)
|
||||
if response.status_code in [401]:
|
||||
raise ConnectionRefusedError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.")
|
||||
|
||||
elif re.match('4\\d\\d', response.status_code):
|
||||
raise ConnectionError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.")
|
||||
if response.status_code in [401, 404]:
|
||||
raise Exception(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.")
|
||||
|
||||
peer_json = json.loads(response.text)
|
||||
for current_peer_map in peer_json:
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
[
|
||||
{
|
||||
"accessible_peers_count": 1,
|
||||
"approval_required": false,
|
||||
"city_name": "",
|
||||
"connected": false,
|
||||
"connection_ip": "",
|
||||
"country_code": "",
|
||||
"dns_label": "apple.netbird.cloud",
|
||||
"geoname_id": 0,
|
||||
"groups": [
|
||||
{
|
||||
"id": "3aBcD4eF5gHiJ6kLmNoP",
|
||||
"name": "All",
|
||||
"peers_count": 2
|
||||
},
|
||||
{
|
||||
"id": "2j3k4l5m6n7o8p9q0r1",
|
||||
"name": "Test Group With Spaces",
|
||||
"peers_count": 1
|
||||
}
|
||||
],
|
||||
"hostname": "apple",
|
||||
"id": "2j3k4l5m6n7o8p9q0r1",
|
||||
"ip": "10.10.10.123",
|
||||
"kernel_version": "",
|
||||
"last_login": "2024-02-10T22:01:27.744131502Z",
|
||||
"last_seen": "2024-02-11T03:21:42.202104672Z",
|
||||
"login_expiration_enabled": true,
|
||||
"login_expired": false,
|
||||
"name": "apple",
|
||||
"os": "Linux Mint 21.3",
|
||||
"ssh_enabled": false,
|
||||
"ui_version": "netbird-desktop-ui/0.25.7",
|
||||
"user_id": "auth0|abc123xyz4567890defg",
|
||||
"version": "0.25.7"
|
||||
},
|
||||
{
|
||||
"accessible_peers_count": 1,
|
||||
"approval_required": false,
|
||||
"city_name": "New York",
|
||||
"connected": true,
|
||||
"connection_ip": "146.123.45.67",
|
||||
"country_code": "US",
|
||||
"dns_label": "banana.netbird.cloud",
|
||||
"geoname_id": 1234567,
|
||||
"groups": [
|
||||
{
|
||||
"id": "2j3k4l5m6n7o8p9q0r1",
|
||||
"name": "Development",
|
||||
"peers_count": 1
|
||||
},
|
||||
{
|
||||
"id": "3aBcD4eF5gHiJ6kLmNoP",
|
||||
"name": "All",
|
||||
"peers_count": 2
|
||||
}
|
||||
],
|
||||
"hostname": "banana",
|
||||
"id": "hkwJPXNUmGywCLo5S8Wg",
|
||||
"ip": "10.10.10.124",
|
||||
"kernel_version": "",
|
||||
"last_login": "2024-02-02T11:20:05.934889112Z",
|
||||
"last_seen": "2024-02-24T02:59:35.324496386Z",
|
||||
"login_expiration_enabled": false,
|
||||
"login_expired": false,
|
||||
"name": "docker-manager",
|
||||
"os": "Alpine Linux 3.19.1",
|
||||
"ssh_enabled": false,
|
||||
"ui_version": "",
|
||||
"user_id": "",
|
||||
"version": "0.25.5"
|
||||
}
|
||||
]
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
plugin: dominion_solutions.netbird.netbird
|
||||
api_key: nbp_this_is_a_fake_api_key
|
||||
api_url: https://netbird.example.com/api/v1
|
||||
ip_style: plain
|
||||
netbird_connected: False
|
||||
leading_separator: No
|
||||
netbird_groups:
|
||||
- "Test Group With Spaces"
|
||||
groups:
|
||||
connected: connected
|
||||
ssh_hosts: ssh_enabled
|
||||
strict: No
|
||||
keyed_groups:
|
||||
|
||||
compose:
|
||||
ansible_ssh_host: label
|
||||
ansible_ssh_port: 22
|
||||
|
|
@ -58,6 +58,20 @@ def netbird_api_multigroup():
|
|||
return mock_netbird_api
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def netbird_api_spaces_in_group():
|
||||
mock_netbird_api = NetbirdApi(None, None)
|
||||
response_data = []
|
||||
with open('tests/unit/module_utils/inventories/fixtures/peers_spaces_in_group.json') as peers_file:
|
||||
peers_map = json.load(peers_file)
|
||||
for data in peers_map:
|
||||
response_data.append(Peer(data['hostname'], data['dns_label'], data['id'], data))
|
||||
|
||||
mock_netbird_api.ListPeers = MagicMock(return_value=response_data)
|
||||
|
||||
return mock_netbird_api
|
||||
|
||||
|
||||
def test_missing_access_token_lookup(inventory):
|
||||
loader = DataLoader()
|
||||
inventory._options = {'api_key': None, 'api_url': None}
|
||||
|
|
@ -137,3 +151,16 @@ def test_use_ip_address(inventory, netbird_api_multigroup):
|
|||
assert inventory.inventory.groups is not None
|
||||
assert 'All' in inventory.inventory.groups
|
||||
assert 'Development' in inventory.inventory.groups
|
||||
|
||||
|
||||
def test_use_group_with_spaces(inventory, netbird_api_spaces_in_group):
|
||||
loader = DataLoader()
|
||||
path = 'tests/unit/module_utils/inventories/fixtures/spaces_in_group.netbird.yml'
|
||||
inventory._build_client = MagicMock()
|
||||
inventory.client = netbird_api_spaces_in_group
|
||||
inventory.parse(InventoryData(), loader, path, False)
|
||||
assert inventory.inventory is not None
|
||||
assert inventory.inventory.hosts is not None
|
||||
assert inventory.inventory.groups is not None
|
||||
assert 'All' in inventory.inventory.groups
|
||||
assert 'Test Group With Spaces' in inventory.inventory.groups
|
||||
|
|
|
|||
Loading…
Reference in New Issue