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
This commit is contained in:
Salt 2022-08-28 12:01:37 -05:00
parent cc3dcd5aeb
commit 44c96b0442

View File

@ -1,29 +1,36 @@
#!/usr/bin/env ansible-playbook #!/usr/bin/env ansible-playbook
# vim:ft=ansible: # 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: block:
- name: ensure zerotier repo key - name: configure zerotier for apt
ansible.builtin.apt_key: url="{{ zerotier_repo_deb_key }}" block:
- name: ensure zerotier repo - name: ensure zerotier repo key
ansible.builtin.apt_repository: repo="{{ zerotier_repo_deb }}" ansible.builtin.apt_key: url="{{ zerotier_repo_deb_key }}"
- name: update apt cache - name: ensure zerotier repo
ansible.builtin.apt: update_cache=yes cache_valid_time=86400 ansible.builtin.apt_repository: repo="{{ zerotier_repo_deb }}"
- name: ensure packages - name: update apt cache
ansible.builtin.apt: name=zerotier-one ansible.builtin.apt: update_cache=yes cache_valid_time=86400
when: ansible_pkg_mgr == "apt" - name: ensure packages
- name: template unit file ansible.builtin.apt: name=zerotier-one
ansible.builtin.template: src=zerotier-one.service dest=/etc/systemd/system/zerotier-one.service mode=0644 when: ansible_pkg_mgr == "apt"
notify: restart zerotier - name: template unit file
- name: join networks ansible.builtin.template: src=zerotier-one.service dest=/etc/systemd/system/zerotier-one.service mode=0644
ansible.builtin.command: notify: restart zerotier
argv: [ zerotier-cli, join, "{{ item }}" ] - name: join networks
with_items: "{{ zerotier_networks_join }}" ansible.builtin.command:
changed_when: no 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 - name: leave networks
ansible.builtin.command: ansible.builtin.command:
argv: [ zerotier-cli, leave, "{{ item }}" ] argv: [ zerotier-cli, leave, "{{ item }}" ]
register: zerotierleave register: zerotierleave
with_items: "{{ zerotier_networks_leave }}" with_items: "{{ zerotier_networks_leave }}"
when: zerotier_cli_path.stat.exists and zerotier_networks_leave is defined
changed_when: no changed_when: no
failed_when: "'0 leave connection failed' in zerotierleave.stdout" failed_when: "'0 leave connection failed' in zerotierleave.stdout"