From 0158c0610ccd49b6b324b6ef8ea6645ed4e5a817 Mon Sep 17 00:00:00 2001 From: "Mark J. Horninger" Date: Mon, 5 Feb 2024 13:50:49 -0500 Subject: [PATCH] Initial commit --- .gitignore | 196 ++++++++++++++++++++++++++++++++++++++ .gitlab-ci.yml | 3 + netbird/README.md | 50 ++++++++++ netbird/defaults/main.yml | 2 + netbird/handlers/main.yml | 2 + netbird/meta/main.yml | 59 ++++++++++++ netbird/tasks/main.yml | 24 +++++ netbird/tests/inventory | 2 + netbird/tests/test.yml | 5 + netbird/vars/main.yml | 2 + requirements.txt | 10 ++ 11 files changed, 355 insertions(+) create mode 100644 .gitignore create mode 100644 .gitlab-ci.yml create mode 100644 netbird/README.md create mode 100644 netbird/defaults/main.yml create mode 100644 netbird/handlers/main.yml create mode 100644 netbird/meta/main.yml create mode 100644 netbird/tasks/main.yml create mode 100644 netbird/tests/inventory create mode 100644 netbird/tests/test.yml create mode 100644 netbird/vars/main.yml create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99c9557 --- /dev/null +++ b/.gitignore @@ -0,0 +1,196 @@ +# Created by https://www.toptal.com/developers/gitignore/api/ansible,python,venv,virtualenv +# Edit at https://www.toptal.com/developers/gitignore?templates=ansible,python,venv,virtualenv + +### Ansible ### +*.retry + +### Python ### +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +### venv ### +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +pip-selfcheck.json + +### VirtualEnv ### +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ + +# End of https://www.toptal.com/developers/gitignore/api/ansible,python,venv,virtualenv + diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..7f59751 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,3 @@ +image: python:3.17-alpine3.19 +before_script: + - pip install -r requirements.txt diff --git a/netbird/README.md b/netbird/README.md new file mode 100644 index 0000000..763665b --- /dev/null +++ b/netbird/README.md @@ -0,0 +1,50 @@ +Role Name +========= +A role that installs the very basic version of Netbird, utilizing their install scripts. + +Requirements +------------ +- curl + +Role Variables +-------------- +- `netbird_setup_key`: The key that is used to automate the setup process. +- `netbird_register`: A true/false defining whether or not register netbird. + +Dependencies +------------ +- None + +Example Playbook +---------------- +```yml +--- +- name: Install Netbird + hosts: localhost + become: true + vars: + netbird_setup_key: "{{ lookup('env', 'NETBIRD_SETUP_KEY') }}" + netbird_register: true + tasks: + - name: Check for netbird setup key + ansible.builtin.fail: + msg: "netbird_setup_key is required" + when: netbird_setup_key is not defined + + - name: Install Netbird + ansible.builtin.include_role: + name: netbird + + - name: Check Netbird Status + ansible.builtin.shell: | + netbird status --detail +``` + +License +------- +MIT + +Author Information +------------------ +- Mark J. Horninger +- Many thanks to [Benjamin Arntzen](https://github.com/Zorlin) for his role that served as a guideline to build this role. diff --git a/netbird/defaults/main.yml b/netbird/defaults/main.yml new file mode 100644 index 0000000..0c37aa2 --- /dev/null +++ b/netbird/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for netbird diff --git a/netbird/handlers/main.yml b/netbird/handlers/main.yml new file mode 100644 index 0000000..f1d037e --- /dev/null +++ b/netbird/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for netbird diff --git a/netbird/meta/main.yml b/netbird/meta/main.yml new file mode 100644 index 0000000..35b0474 --- /dev/null +++ b/netbird/meta/main.yml @@ -0,0 +1,59 @@ +galaxy_info: + author: Mark Horninger + description: your role description + company: Dominion Solutions LLC + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: MIT + + min_ansible_version: 9.2.0 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: + - mesh + - net + - netbird + - network + - security + - vpn + - wireguard + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/netbird/tasks/main.yml b/netbird/tasks/main.yml new file mode 100644 index 0000000..0e102cb --- /dev/null +++ b/netbird/tasks/main.yml @@ -0,0 +1,24 @@ +--- +# tasks file for netbird +- name: Check for Netbird Installation + ansible.builtin.shell: + cmd: netbird --version + ignore_errors: true + register: netbird_installed + +- name: Install netbird + ansible.builtin.shell: curl -fsSL https://pkgs.netbird.io/install.sh | sh + when: netbird_installed.rc != 0 + +- name: Ensure netbird is not up + shell: + cmd: 'netbird status | grep "Daemon status"' + register: netbird_status + changed_when: false + ignore_errors: true + when: netbird_register is true + +- name: Start Netbird + become: true + ansible.builtin.shell: netbird up --setup-key="{{ netbird_setup_key }}" + when: netbird_register is true and 'NeedsLogin' in netbird_status.stdout diff --git a/netbird/tests/inventory b/netbird/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/netbird/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/netbird/tests/test.yml b/netbird/tests/test.yml new file mode 100644 index 0000000..738ff20 --- /dev/null +++ b/netbird/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - netbird diff --git a/netbird/vars/main.yml b/netbird/vars/main.yml new file mode 100644 index 0000000..b57bb1b --- /dev/null +++ b/netbird/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for netbird diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..c11843b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +ansible==9.2.0 +ansible-core==2.16.3 +cffi==1.16.0 +cryptography==42.0.2 +Jinja2==3.1.3 +MarkupSafe==2.1.5 +packaging==23.2 +pycparser==2.21 +PyYAML==6.0.1 +resolvelib==1.0.1