22 Commits

Author SHA1 Message Date
Marcus
6afd96758f Merge pull request #16 from m4rcu5nl/develop
Version 1
2018-04-05 02:18:34 +02:00
Marcus Meurs
8564a01220 Merge branch 'feature/optional_member_description' into develop 2018-04-05 01:32:27 +02:00
Marcus Meurs
8f5f3c7181 Description option added
- Added description to API call. Defaults to empty string.
- Variable descriptoin and example added to readme
2018-04-05 01:32:16 +02:00
Marcus Meurs
b5544a53aa Tests as filters deprecated
"Using Ansible-provided Jinja tests as filters is deprecated and will be removed in Ansible 2.9."
2018-04-05 00:20:10 +02:00
Marcus Meurs
5a8ff53813 Better ip_assignments example
Setting that variable on play level would try to assign the same list of ip addresses to every host in servers group.
2018-04-05 00:12:35 +02:00
Marcus Meurs
1471a825b2 Bump versions 2018-04-04 02:18:32 +02:00
Marcus
401536c7db Merge pull request #15 from andyshinn/fixes
Some fixes, changes, and modularizing
2018-04-04 01:50:34 +02:00
Andy Shinn
f1cc5c4e49 somes fixups 2018-02-15 19:59:14 -06:00
Marcus
c6cacd05ef Merge pull request #12 from flantel/master
Update install.yml to fix fresh Debian install.
2018-02-04 23:43:19 +01:00
Marcus
9f9e2deaac Merge branch 'master' into master 2018-02-04 23:38:45 +01:00
Barry Flanagan
054d554a4d Update install.yml to fix fresh Debian install.
Fresh install was failing if the zerotier repo did not exist. Changed the initial check to check the existence of the zerotier repo file.
2018-02-04 22:31:33 +00:00
Marcus
f82ab21515 Merge pull request #11 from m4rcu5nl/develop
Debian support added
2018-01-29 22:29:36 +01:00
Marcus Meurs
03786a8f7d Added Debian support to meta file
Also removed "yum repo" from readme to reflect multi platform support.
2018-01-29 22:21:51 +01:00
Marcus
3b0cdf725f Merge pull request #10 from flantel/master
Add support for Debian distros
2018-01-29 21:45:23 +01:00
Barry flanagan
5ab3e67331 Add support for Debian distros 2018-01-29 15:11:08 +00:00
Marcus
097a4f055b Merge pull request #9 from m4rcu5nl/develop
Bug fixes
2017-12-17 05:59:41 +01:00
Marcus
62682def92 Merge pull request #8 from m4rcu5nl/feature/skip_tasks_in_check_mode
Resolved errors in check-mode
2017-12-17 05:52:44 +01:00
Marcus Meurs
c90f7556c2 Resolved errors in check-mode
Fixes #3
2017-12-17 05:49:36 +01:00
Marcus
9b6296e678 Merge pull request #7 from m4rcu5nl/feature/import_tasks_propperly
Move away from deprecated way to include tasks
2017-12-17 05:40:03 +01:00
Marcus Meurs
51d2085c02 Move away from deprecated way to include tasks
Fixes #6
2017-12-17 05:32:14 +01:00
Marcus
e70be64ef7 Merge pull request #5 from gbraad/patch-1
Change headers for rendering
2017-09-11 16:51:46 +02:00
Gerard Braad
769e901ca1 Change headers for rendering
... and make example into code-block with syntax definition
2017-09-11 11:33:20 +08:00
10 changed files with 128 additions and 66 deletions

View File

@@ -1,36 +1,75 @@
[![Build Status](https://travis-ci.org/m4rcu5nl/ansible-role-zerotier.svg?branch=master)](https://travis-ci.org/m4rcu5nl/ansible-role-zerotier) [![GitHub issues](https://img.shields.io/github/issues/m4rcu5nl/ansible-role-zerotier.svg)](https://github.com/m4rcu5nl/ansible-role-zerotier/issues)
Zerotier
ZeroTier
=========
This Ansible role installs the zerotier-one package from Zerotier's yum repo, adds and authorizes new members to (existing) Zerotier network and tells the new members to join the network.
This Ansible role installs the `zerotier-one` package, adds and authorizes new members to (existing) ZeroTier networks, and tells the new member to join the network.
Requirements
------------
This roles requires an access token for the Zerotier API. This enables the role to add new members to a private network and authorizes them. Also, the role needs the network ID of the Zerotier network the new members should join.
This role has an optional access token variable to authorize the member using the ZeroTier API. The role also takes the ID of the ZeroTier network to automatically join the new member.
Role Variables
--------------
###zerotier_api_url
The url where the Zerotier API lives. Must use https protocol.
### zerotier_api_url
The url where the Zerotier API lives. Must use HTTPS protocol.
Default: https://my.zerotier.com
###zerotier_accesstoken
The access token needed to authorize with the Zerotier API. You can generate one in your account settings on my.zerotier.com.
### zerotier_accesstoken
The access token needed to authorize with the ZeroTier API. You can generate one in your account settings at https://my.zerotier.com/. If this is left out then the newly joined member will not be automatically authorized.
###zerotier_network_id (required)
The 16 character network ID of the network the new members should join.
### zerotier_network_id
The 16 character network ID of the network the new members should join. The node will not join any network if omitted.
### zerotier_register_short_hostname
Used to register the short hostname (without the FQDN) on the network instead of the long one.
Default: `false`
### zerotier_member_ip_assignments
A list of IP addresses to assign this member. The member will be automatically assigned an address on the network if left out.
### zerotier_member_description
Optional desription for a member.
Example Playbook
----------------
```yaml
- hosts: servers
vars:
zerotier_network_id: 1234567890qwerty
zerotier_accesstoken: "{{ vault_zerotier_accesstoken }}"
zerotier_register_short_hostname: true
roles:
- { role: m4rcu5nl.zerotier }
```
Example Inventory
----------------
```INI
[servers]
web1.example.com zerotier_member_ip_assignments='["192.168.195.1", "192.168.195.2"]'
web2.example.com zerotier_member_ip_assignments='["192.168.195.3", "192.168.195.4"'
db1.example.com zerotier_member_ip_assignments='["192.168.195.10"]'
db2.example.com zerotier_member_ip_assignments='["192.168.195.11"]'
db3.example.com zerotier_member_ip_assignments='["192.168.195.12"]'
[webservers]
web1.example.com
web2.example.com
[dbservers]
db1.example.com
db2.example.com
db3.example.com
[webservers:vars]
zerotier_member_description='<AppName> webserver'
[dbservers:vars]
zerotier_member_description='<AppName> db cluster node'
```

View File

@@ -1,3 +1,6 @@
---
# defaults file for ansible-role-zerotier
zerotier_api_url: https://my.zerotier.com
zerotier_apt_state: present
zerotier_register_short_hostname: false
zerotier_authorize_member: true

View File

@@ -16,7 +16,7 @@ galaxy_info:
# - CC-BY
license: BSD
min_ansible_version: 2.0
min_ansible_version: 2.4
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
@@ -36,6 +36,9 @@ galaxy_info:
- name: EL
versions:
- 7
- name: Debian
versions:
- stretch
# - name: Fedora
# versions:
# - all
@@ -49,7 +52,7 @@ galaxy_info:
galaxy_tags:
- zerotier-one
- CentOS 7
- networking
# 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.

32
tasks/authorize_node.yml Normal file
View File

@@ -0,0 +1,32 @@
---
- block:
- name: Get Zerotier NodeID
shell: zerotier-cli info | awk '{print $3}'
register: nodeid
changed_when: false
- name: Set NodeID as fact
set_fact:
zerotier_node_id: "{{ nodeid.stdout }}"
- name: Add and authorize members to network
uri:
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ zerotier_node_id }}"
method: POST
headers:
Authorization: bearer {{ zerotier_accesstoken }}
body:
name: "{{ zerotier_register_short_hostname | ternary(inventory_hostname_short, inventory_hostname) }}"
description: "{{ zerotier_member_description | default() }}"
hidden: false
config:
authorized: "{{ zerotier_authorize_member }}"
ipAssignments: "{{ zerotier_member_ip_assignments | default([]) | list }}"
body_format: json
register: apiresult
when:
- zerotier_accesstoken is defined
- not ansible_check_mode
tags:
- configuration

View File

@@ -1,19 +1,6 @@
---
- block: # Add zerotier repo and it's gpg key
- name: Add zerotier gpg key
rpm_key:
state: present
key: https://download.zerotier.com/contact%40zerotier.com.gpg
- name: Add zerotier repo
yum_repository:
name: zerotier
description: ZeroTier, Inc. RPM Release Repository
baseurl: https://download.zerotier.com/redhat/el/$releasever
gpgcheck: yes
enabled: yes
register: zerotier_repo
- include_tasks: install/{{ ansible_os_family }}.yml
tags:
- installation
- repositories
@@ -30,12 +17,13 @@
name: zerotier-one
state: started
when:
- zerotier_client|succeeded
- zerotier_client is succeeded
notify:
- enable zerotier-one
when:
- zerotier_repo|succeeded
- zerotier_repo is succeeded
- not ansible_check_mode
tags:
- installation
- packages

9
tasks/install/Debian.yml Normal file
View File

@@ -0,0 +1,9 @@
- name: Add ZeroTier PGP key
apt_key:
url: "{{ zerotier_gpg_url }}"
- name: Add ZeroTier APT repository
apt_repository:
repo: deb {{ zerotier_download_base_url }}/debian/{{ ansible_distribution_release }} {{ ansible_distribution_release }} main
filename: zerotier
register: zerotier_repo

13
tasks/install/RedHat.yml Normal file
View File

@@ -0,0 +1,13 @@
- name: Add ZeroTier gpg key
rpm_key:
state: present
key: "{{ zerotier_gpg_url }}"
- name: Add ZeroTier repo
yum_repository:
name: zerotier
description: ZeroTier, Inc. RPM Release Repository
baseurl: https://download.zerotier.com/redhat/el/$releasever
gpgcheck: yes
enabled: yes
register: zerotier_repo

View File

@@ -1,33 +1,7 @@
---
- block: # Join Zerotier network
- name: Get Zerotier NodeID
shell: /sbin/zerotier-cli info | awk '{print $3}'
register: nodeid
- name: Set NodeID as fact
set_fact:
zerotier_node_id: "{{ nodeid.stdout }}"
- name: Add and authorize members to network
uri:
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ zerotier_node_id }}"
method: POST
headers:
Authorization: bearer {{ zerotier_accesstoken }}
body:
name: "{{ inventory_hostname }}"
hidden: false
config:
authorized: true
body_format: json
register: apiresult
- name: Join Zerotier network
command: /sbin/zerotier-cli join {{ zerotier_network_id }}
- name: Join ZeroTier network
command: zerotier-cli join {{ zerotier_network_id }}
args:
creates: /var/lib/zerotier-one/networks.d/{{ zerotier_network_id }}.conf
when:
- zerotier_accesstoken is defined
tags:
- configuration

View File

@@ -1,12 +1,11 @@
---
# tasks file for ansible-role-zerotier
- include: install.yml
- import_tasks: install.yml
- name: Check for successfully joined networks
shell: zerotier-cli listnetworks | grep 'OK'| awk '{print $3}'
register: joinednetworks
- include: join_network.yml
- import_tasks: authorize_node.yml
when:
- 'zerotier_network_id not in joinednetworks.stdout'
- zerotier_accesstoken is defined
- import_tasks: join_network.yml
when:
- zerotier_network_id is defined

View File

@@ -1,2 +1,4 @@
---
# vars file for ansible-role-zerotier
zerotier_download_base_url: http://download.zerotier.com
zerotier_gpg_url: https://download.zerotier.com/contact@zerotier.com.gpg