From 44c96b0442a548e8ed35a795ad95f32cdd3c3b07 Mon Sep 17 00:00:00 2001 From: Jacob Babor Date: Sun, 28 Aug 2022 12:01:37 -0500 Subject: [PATCH] Rework zerotier role to prevent installing zerotier just for it to do nothing at all This also neatly avoids things like rpm-ostree-based distros where i install zerotier in a container --- roles/zerotier/tasks/main.yml | 43 ++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/roles/zerotier/tasks/main.yml b/roles/zerotier/tasks/main.yml index 1b16e71..cb53cbc 100644 --- a/roles/zerotier/tasks/main.yml +++ b/roles/zerotier/tasks/main.yml @@ -1,29 +1,36 @@ #!/usr/bin/env ansible-playbook # vim:ft=ansible: --- -- name: configure zerotier for apt +- name: check for zerotier + stat: path=/usr/bin/zerotier-cli + register: zerotier_cli_path +- name: install zerotier if we're joining networks block: - - name: ensure zerotier repo key - ansible.builtin.apt_key: url="{{ zerotier_repo_deb_key }}" - - name: ensure zerotier repo - ansible.builtin.apt_repository: repo="{{ zerotier_repo_deb }}" - - name: update apt cache - ansible.builtin.apt: update_cache=yes cache_valid_time=86400 - - name: ensure packages - ansible.builtin.apt: name=zerotier-one - when: ansible_pkg_mgr == "apt" -- name: template unit file - ansible.builtin.template: src=zerotier-one.service dest=/etc/systemd/system/zerotier-one.service mode=0644 - notify: restart zerotier -- name: join networks - ansible.builtin.command: - argv: [ zerotier-cli, join, "{{ item }}" ] - with_items: "{{ zerotier_networks_join }}" - changed_when: no + - name: configure zerotier for apt + block: + - name: ensure zerotier repo key + ansible.builtin.apt_key: url="{{ zerotier_repo_deb_key }}" + - name: ensure zerotier repo + ansible.builtin.apt_repository: repo="{{ zerotier_repo_deb }}" + - name: update apt cache + ansible.builtin.apt: update_cache=yes cache_valid_time=86400 + - name: ensure packages + ansible.builtin.apt: name=zerotier-one + when: ansible_pkg_mgr == "apt" + - name: template unit file + ansible.builtin.template: src=zerotier-one.service dest=/etc/systemd/system/zerotier-one.service mode=0644 + notify: restart zerotier + - name: join networks + ansible.builtin.command: + argv: [ zerotier-cli, join, "{{ item }}" ] + with_items: "{{ zerotier_networks_join }}" + changed_when: no + when: zerotier_networks_join is defined and zerotier_networks_join - name: leave networks ansible.builtin.command: argv: [ zerotier-cli, leave, "{{ item }}" ] register: zerotierleave with_items: "{{ zerotier_networks_leave }}" + when: zerotier_cli_path.stat.exists and zerotier_networks_leave is defined changed_when: no failed_when: "'0 leave connection failed' in zerotierleave.stdout"