Set custom facts persistently

Create /etc/ansible/facts.d/zerotier.fact on each node containing custom facts in json format. This can then be used to prevent pointless reconfiguration of existing nodes whenever a new one is added to the inventory. In this commit it merely skips the installation tasks.
This commit is contained in:
Marcus Meurs
2018-12-03 07:05:37 +01:00
parent b5cca4baa5
commit c03c2b5a3f
3 changed files with 47 additions and 19 deletions

View File

@@ -1,24 +1,8 @@
---
- 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 }}"
when:
- zerotier_accesstoken is defined
- not ansible_check_mode
tags:
- configuration
- block:
- name: Authorize members to network
uri:
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ zerotier_node_id }}"
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ ansible_local.zerotier.node_id }}"
method: POST
headers:
Authorization: bearer {{ zerotier_accesstoken }}
@@ -32,7 +16,7 @@
- name: Configure members in network
uri:
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ zerotier_node_id }}"
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ ansible_local.zerotier.node_id }}"
method: POST
headers:
Authorization: bearer {{ zerotier_accesstoken }}
@@ -46,7 +30,6 @@
delegate_to: "{{ zerotier_api_delegate }}"
when:
- zerotier_accesstoken is defined
- not ansible_check_mode
tags:
- configuration

View File

@@ -3,10 +3,20 @@
- import_tasks: install.yml
when:
- not skip_install|default(false)|bool
- ansible_local.zerotier is not defined
- block:
- name: Update ansible_local facts
script: set_facts.sh
- name: Re-gather facts
setup: ~
- import_tasks: authorize_node.yml
when:
- zerotier_accesstoken is defined
- ansible_local.zerotier.node_id is defined
- import_tasks: join_network.yml
when: