Skip to content

Commit

Permalink
Variable naming convention
Browse files Browse the repository at this point in the history
Updated 2 variable names to follow naming convention. For backwards compatibility the old names are rewritten to the new ones in the role's defaults.
  • Loading branch information
m4rcu5nl committed Dec 4, 2018
1 parent 618ae55 commit 4dac800
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
64 changes: 40 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,54 @@
ZeroTier
=========

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.
This Ansible role adds the ZeroTier repository and installs the `zerotier-one` package using your system's package manager. Depending on the provided variables this role can also add and authorize new members to (existing) ZeroTier networks, and tell the new member to join the network.

Requirements
------------

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.
Technically this role has no requirements. If it's ran without any variables set it will only run the installation tasks. The following variables impact the role's behavior:

Role Variables
--------------

### 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 at https://my.zerotier.com/. If this is left out then the newly joined member will not be automatically authorized.
[**zerotier_network_id**](#zerotier_network_id): when set hosts are told to join this network.
[**zerotier_api_accesstoken**](#zerotier_api_accesstoken): when set the role can handle member authentication and configuration using the ZeroTier API.

### 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.
Role Variables
--------------

### zerotier_api_delegate
Option to delegate tasks for Zerotier API calls. By default the API calls are made from the machine running the role.
#### zerotier_network_id
*Type*: string
*Default value*:
*Description*: The 16 character network ID of the network the new members should join. The node will not join any network if omitted.

#### zerotier_member_register_short_hostname
*Type*: boolean
*Default value*: `false`
*Description*: Used to register the short hostname (without the FQDN) on the network instead of the long one.

#### zerotier_member_ip_assignments
*Type*: list
*Default value*: `[]`
*Description*: 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
*Type*: string
*Default value*:
*Description*: Optional desription for a member.

#### zerotier_api_accesstoken
*Type*: string
*Default value*:
*Description*: 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_api_url
*Type*: string
*Default value*: `https://my.zerotier.com`
*Description*: The url where the Zerotier API lives. Must use HTTPS protocol.

#### zerotier_api_delegate
*Type*: string
*Default value*: `localhost`
*Description*: Option to delegate tasks for Zerotier API calls. By default the API calls are made from the machine running the role.

Example Playbook
----------------
Expand Down
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
---
# defaults file for ansible-role-zerotier
zerotier_api_accesstoken: "{{ zerotier_accesstoken | default() }}" # For backwards compatibility
zerotier_api_url: https://my.zerotier.com
zerotier_api_delegate: localhost
zerotier_apt_state: present
zerotier_register_short_hostname: false
zerotier_member_register_short_hostname: "{{ zerotier_register_short_hostname | default(false) }}" # For backwards compatibility
zerotier_authorize_member: true
6 changes: 3 additions & 3 deletions tasks/authorize_node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ ansible_local.zerotier.node_id }}"
method: POST
headers:
Authorization: bearer {{ zerotier_accesstoken }}
Authorization: bearer {{ zerotier_api_accesstoken }}
body:
hidden: false
config:
Expand All @@ -21,9 +21,9 @@
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ ansible_local.zerotier.node_id }}"
method: POST
headers:
Authorization: bearer {{ zerotier_accesstoken }}
Authorization: bearer {{ zerotier_api_accesstoken }}
body:
name: "{{ zerotier_register_short_hostname | ternary(inventory_hostname_short, inventory_hostname) }}"
name: "{{ zerotier_member_register_short_hostname | ternary(inventory_hostname_short, inventory_hostname) }}"
description: "{{ zerotier_member_description | default() }}"
config:
ipAssignments: "{{ zerotier_member_ip_assignments | default([]) | list }}"
Expand Down
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

- import_tasks: authorize_node.yml
when:
- zerotier_accesstoken is defined
- zerotier_api_accesstoken | length > 0
- ansible_local.zerotier.node_id is defined

- import_tasks: join_network.yml
Expand Down

0 comments on commit 4dac800

Please sign in to comment.