Guest User

Untitled

a guest
Jul 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. ---
  2. - hosts: all
  3. # run this: ansible-playbook -i lil_box.local, -u $USER .configure-syncthing.yaml --ask-become-pass
  4. # beforehand you need to:
  5. # ssh-copy-id -i $remoteserver
  6. # as well as:
  7. # ssh-copy-id -i localhost
  8.  
  9. vars:
  10. sync_dir: "{{ ansible_env.HOME }}/Sync"
  11.  
  12. tasks:
  13.  
  14. - name: install necessary packages
  15. apt: pkg={{ item }} update_cache=yes cache_valid_time=3600
  16. become: yes
  17. with_items:
  18. - syncthing
  19.  
  20. - name: install pip3 packages
  21. pip: name={{ item }} extra_args="--upgrade" executable=pip3
  22. become: yes
  23. with_items:
  24. - syncthingmanager
  25.  
  26. - name: configure device
  27. command: stman configure
  28. args:
  29. creates: "{{ ansible_env.HOME }}/.config/syncthingmanager/syncthingmanager.conf"
  30.  
  31. - name: get locally configured devices
  32. shell: stman device list
  33. delegate_to: localhost
  34. register: local_devices
  35.  
  36. - name: get remotely configured devices
  37. command: stman device list
  38. register: remote_devices
  39.  
  40. - name: get DEVICEIDs
  41. set_fact:
  42. lil_box_deviceid: "{{ remote_devices.stdout_lines[1].split()[1] }}"
  43. big_box_deviceid: "{{ local_devices.stdout_lines[1].split()[1] }}"
  44.  
  45. - name: investigate
  46. debug:
  47. var: lil_box_deviceid
  48. # var: local_devices
  49.  
  50. - name: investigate
  51. debug:
  52. msg: "Already added {{ big_box_deviceid }} remotely"
  53. when: big_box_deviceid in remote_devices.stdout
  54.  
  55. - name: add {{ big_box_deviceid }}
  56. command: stman device add -i {{ big_box_deviceid }}
  57. register: res_big_box
  58. when: big_box_deviceid not in remote_devices.stdout
  59.  
  60. - name: add default folder remotely
  61. command: stman folder add {{ sync_dir }} default
  62. args:
  63. creates: "{{ sync_dir }}"
  64.  
  65. - name: add remote device locally
  66. shell: stman device add {{ lil_box_deviceid }}
  67. delegate_to: localhost
  68. register: res_local
  69. when: lil_box_deviceid not in local_devices.stdout
  70.  
  71. - name: get shared local folders
  72. shell: stman folder list
  73. delegate_to: localhost
  74. register: local_folders
  75.  
  76. - name: share local default folder remote device
  77. shell: stman folder share default {{ lil_box_deviceid }}
  78. delegate_to: localhost
  79. when: "ansible_hostname not in local_folders.stdout_lines[1]"
  80. # when: lil_box_deviceid in local_devices.stdout or res_local.failed is defined and not res_local.failed
  81.  
  82. - name: restart syncthing
  83. systemd: name=syncthing state=restarted enabled=yes user=yes
Add Comment
Please, Sign In to add comment