Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ---
- - hosts: all
- # run this: ansible-playbook -i lil_box.local, -u $USER .configure-syncthing.yaml --ask-become-pass
- # beforehand you need to:
- # ssh-copy-id -i $remoteserver
- # as well as:
- # ssh-copy-id -i localhost
- vars:
- sync_dir: "{{ ansible_env.HOME }}/Sync"
- tasks:
- - name: install necessary packages
- apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
- become: yes
- with_items:
- - syncthing
- - name: install pip3 packages
- pip: name={{ item }} extra_args="--upgrade" executable=pip3
- become: yes
- with_items:
- - syncthingmanager
- - name: configure device
- command: stman configure
- args:
- creates: "{{ ansible_env.HOME }}/.config/syncthingmanager/syncthingmanager.conf"
- - name: get locally configured devices
- shell: stman device list
- delegate_to: localhost
- register: local_devices
- - name: get remotely configured devices
- command: stman device list
- register: remote_devices
- - name: get DEVICEIDs
- set_fact:
- lil_box_deviceid: "{{ remote_devices.stdout_lines[1].split()[1] }}"
- big_box_deviceid: "{{ local_devices.stdout_lines[1].split()[1] }}"
- - name: investigate
- debug:
- var: lil_box_deviceid
- # var: local_devices
- - name: investigate
- debug:
- msg: "Already added {{ big_box_deviceid }} remotely"
- when: big_box_deviceid in remote_devices.stdout
- - name: add {{ big_box_deviceid }}
- command: stman device add -i {{ big_box_deviceid }}
- register: res_big_box
- when: big_box_deviceid not in remote_devices.stdout
- - name: add default folder remotely
- command: stman folder add {{ sync_dir }} default
- args:
- creates: "{{ sync_dir }}"
- - name: add remote device locally
- shell: stman device add {{ lil_box_deviceid }}
- delegate_to: localhost
- register: res_local
- when: lil_box_deviceid not in local_devices.stdout
- - name: get shared local folders
- shell: stman folder list
- delegate_to: localhost
- register: local_folders
- - name: share local default folder remote device
- shell: stman folder share default {{ lil_box_deviceid }}
- delegate_to: localhost
- when: "ansible_hostname not in local_folders.stdout_lines[1]"
- # when: lil_box_deviceid in local_devices.stdout or res_local.failed is defined and not res_local.failed
- - name: restart syncthing
- systemd: name=syncthing state=restarted enabled=yes user=yes
Add Comment
Please, Sign In to add comment