Merge pull request #2 from m4rcu5nl/develop

First beta release
pull/5/head v0.1-beta.1
Marcus 2017-07-27 02:27:20 +02:00 committed by GitHub
commit 771661816f
11 changed files with 218 additions and 18 deletions

29
.travis.yml Normal file
View File

@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@ -1,38 +1,36 @@
Role Name [![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
========= =========
A brief description of the role goes here. 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.
Requirements Requirements
------------ ------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. 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.
Role Variables Role Variables
-------------- --------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. ###zerotier_api_url
The url where the Zerotier API lives. Must use https protocol.
Default: https://my.zerotier.com
Dependencies ###zerotier_accesstoken
------------ The access token needed to authorize with the Zerotier API. You can generate one in your account settings on my.zerotier.com.
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. ###zerotier_network_id (required)
The 16 character network ID of the network the new members should join.
Example Playbook Example Playbook
---------------- ----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers - hosts: servers
vars:
zerotier_network_id: 1234567890qwerty
zerotier_accesstoken: "{{ vault_zerotier_accesstoken }}"
roles: roles:
- { role: username.rolename, x: 42 } - { role: m4rcu5nl.zerotier }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

3
defaults/main.yml Normal file
View File

@ -0,0 +1,3 @@
---
# defaults file for ansible-role-zerotier
zerotier_api_url: https://my.zerotier.com

13
handlers/main.yml Normal file
View File

@ -0,0 +1,13 @@
---
# handlers file for ansible-role-zerotier
- name: start zerotier-one
service: name=zerotier-one status=started
- name: stop zerotier-one
service: name=zerotier-one status=stopped
- name: restart zerotier-one
service: name=zerotier-one status=restarted
- name: enable zerotier-one
service: name=zerotier-one enabled=yes

62
meta/main.yml Normal file
View File

@ -0,0 +1,62 @@
galaxy_info:
author: Marcus Meurs
description: Install zerotier-one package and add new members to a zerotier network
company: NULL
# 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
# Some suggested licenses:
# - BSD (default)
# - MIT
# - GPLv2
# - GPLv3
# - Apache
# - CC-BY
license: BSD
min_ansible_version: 2.0
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
# Optionally specify the branch Galaxy will use when accessing the GitHub
# repo for this role. During role install, if no tags are available,
# Galaxy will use this branch. During import Galaxy will access files on
# this branch. If Travis integration is configured, only notifications for this
# branch will be accepted. Otherwise, in all cases, the repo's default branch
# (usually master) will be used.
#github_branch:
#
# platforms is a list of platforms, and each platform has a name and a list of versions.
#
platforms:
- name: EL
versions:
- 7
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags:
- zerotier-one
- CentOS 7
# 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.

41
tasks/install.yml Normal file
View File

@ -0,0 +1,41 @@
---
- 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
tags:
- installation
- repositories
- block: #Install and enable zerotier-one
- name: Install zerotier-one
package:
name: zerotier-one
state: present
register: zerotier_client
- name: Start zerotier-one service
service:
name: zerotier-one
state: started
when:
- zerotier_client|succeeded
notify:
- enable zerotier-one
when:
- zerotier_repo|succeeded
tags:
- installation
- packages

33
tasks/join_network.yml Normal file
View File

@ -0,0 +1,33 @@
---
- 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 }}
args:
creates: /var/lib/zerotier-one/networks.d/{{ zerotier_network_id }}.conf
when:
- zerotier_accesstoken is defined
tags:
- configuration

12
tasks/main.yml Normal file
View File

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

2
tests/inventory Normal file
View File

@ -0,0 +1,2 @@
localhost

5
tests/test.yml Normal file
View File

@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ansible-role-zerotier

2
vars/main.yml Normal file
View File

@ -0,0 +1,2 @@
---
# vars file for ansible-role-zerotier