main.yml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. - name: Install dependencies for this role
  2. apt:
  3. pkg: "{{ item }}"
  4. state: present
  5. with_items:
  6. - bridge-utils
  7. - ebtables
  8. - git
  9. - iproute
  10. - libevent-dev
  11. - libnetfilter-conntrack3
  12. - python-dev
  13. - python-virtualenv
  14. # additional dependencies for wlanslovenija's version
  15. # - libffi-dev
  16. # - libnfnetlink-dev
  17. # - libnetfilter-conntrack-dev
  18. # - gcc
  19. when: domaenenliste is defined
  20. - name: Determine whether the global version of tunneldigger is installed or not
  21. stat: path=/lib/systemd/system/tunneldigger.service
  22. register: _td_global_installed
  23. when: domaenenliste is defined
  24. - name: Determine whether the per domain version of tunneldigger is installed or not
  25. stat: path=/lib/systemd/system/tunneldigger@.service
  26. register: _td_per_domain_installed
  27. when: domaenenliste is defined
  28. - name: Get all enabled tunneldigger (domain specific) instances
  29. shell: '/bin/ls /etc/systemd/system/multi-user.target.wants/tunneldigger@* | grep -oE "[0-9]+"'
  30. changed_when: False
  31. failed_when: False
  32. check_mode: no
  33. register: _td_domain_instances
  34. when: domaenenliste is defined
  35. # remove /etc/systemd/system/tunneldigger.service if it's not a symlink (issue within older versie of this role, may can be removed in the future)
  36. - name: Remove tunneldigger.service from systemd's local config if it isn't a symlink
  37. file: path=/etc/systemd/system/tunneldigger.service state=absent
  38. register: _old_td_systemd
  39. when: domaenenliste is defined
  40. - name: Stop and disable obsolete td instances
  41. service: name="tunneldigger@{{item}}.service" enabled=no state=stopped
  42. with_items: "{{_td_domain_instances.stdout_lines}}"
  43. when: domaenenliste is defined and (item not in domaenenliste or tunneldigger.instance_per_domain == False) and _td_per_domain_installed.stat.exists == True
  44. - name: Stop global td instance if change to per domain instances is ongoing
  45. service: name="tunneldigger.service" enabled=no state=stopped
  46. when:
  47. - domaenenliste is defined
  48. - tunneldigger.instance_per_domain == True and (_td_global_installed.stat.exists == True or _old_td_systemd.changed == True)
  49. - name: Delete global td systemd config if change to per domain instances is ongoing
  50. file: path=/lib/systemd/system/tunneldigger.service state=absent
  51. when:
  52. - domaenenliste is defined
  53. - tunneldigger.instance_per_domain == True and (_td_global_installed.stat.exists == True or _old_td_systemd.changed == True)
  54. - name: Delete per domain td systemd config if change to global td is ongoing
  55. file: path=/lib/systemd/system/tunneldigger@.service state=absent
  56. when:
  57. - domaenenliste is defined
  58. - tunneldigger.instance_per_domain == False and _td_per_domain_installed.stat.exists == True
  59. # tasks for wlanslovenija's version
  60. # - name: git für tunneldigger
  61. # git: repo=https://github.com/wlanslovenija/tunneldigger dest=/srv/tunneldigger force=yes update=yes version=235e111fb8fa02c4687af7f695e21204d9d28fe6
  62. # - name: Install python dependencies
  63. # shell: "/srv/tunneldigger/bin/python /srv/tunneldigger/broker/setup.py install"
  64. # args:
  65. # chdir: /srv/tunneldigger/broker/
  66. - name: Remove repository if td mode change is ongoing
  67. file: path=/srv/tunneldigger state=absent
  68. when:
  69. - domaenenliste is defined
  70. - (tunneldigger.instance_per_domain == False and _td_per_domain_installed.stat.exists == True) or (tunneldigger.instance_per_domain == True and (_td_global_installed.stat.exists == True or _old_td_systemd.changed == True))
  71. #- name: Clone tunneldigger (wlanslovenija fork)
  72. # git: repo=https://github.com/wlanslovenija/tunneldigger dest=/srv/tunneldigger force=yes update=yes
  73. # when: domaenenliste is defined
  74. - name: Clone tunneldigger (ffrl fork)
  75. git: repo=https://github.com/ffrl/tunneldigger dest=/srv/tunneldigger force=yes update=yes version=e6b09f365f8d3459488680840feb77c54a9c9668
  76. when: domaenenliste is defined
  77. - name: patch l2tp_broker.py if mode is global
  78. patch: src=l2tp_broker.py.patch dest=/srv/tunneldigger/broker/l2tp_broker.py
  79. when:
  80. - domaenenliste is defined
  81. - tunneldigger.instance_per_domain == False
  82. - name: Install python dependencies
  83. pip: requirements=/srv/tunneldigger/broker/requirements.txt virtualenv=/srv/tunneldigger
  84. when: domaenenliste is defined
  85. - name: Deploy addif.sh for each domain
  86. template: src=addif.sh.j2 dest="/srv/tunneldigger/broker/scripts/addif_domain{{item.key}}.sh" mode=0755
  87. with_dict: "{{domaenenliste}}"
  88. when:
  89. - domaenenliste is defined
  90. - tunneldigger.instance_per_domain == True
  91. - name: Deploy addif.sh if mode is global
  92. copy: src=addif.sh dest=/srv/tunneldigger/broker/scripts mode=0755
  93. when:
  94. - domaenenliste is defined
  95. - tunneldigger.instance_per_domain == False
  96. - name: Deploy delif.sh for each domain
  97. template: src=delif.sh.j2 dest="/srv/tunneldigger/broker/scripts/delif_domain{{item.key}}.sh" mode=0755
  98. with_dict: "{{domaenenliste}}"
  99. when:
  100. - domaenenliste is defined
  101. - tunneldigger.instance_per_domain == True
  102. - name: Deploy delif.sh if mode is global
  103. copy: src=delif.sh dest=/srv/tunneldigger/broker/scripts mode=0755
  104. when:
  105. - domaenenliste is defined
  106. - tunneldigger.instance_per_domain == False
  107. - name: Create sperrliste.txt if not exists
  108. command: touch /srv/tunneldigger/broker/scripts/sperrliste.txt
  109. args:
  110. creates: /srv/tunneldigger/broker/scripts/sperrliste.txt
  111. when: domaenenliste is defined
  112. - name: Deploy tunneldigger.conf to /etc/modules-load.d/
  113. copy: src=tunneldigger.conf dest=/etc/modules-load.d/tunneldigger.conf
  114. notify: load kernel modules
  115. when: domaenenliste is defined
  116. - name: Deploy l2tp_broker.cfg for each domain
  117. template: src="l2tp_broker.cfg.j2" dest="/srv/tunneldigger/broker/l2tp_broker_domain{{item.key}}.cfg"
  118. notify: restart tunneldigger per domain
  119. with_dict: "{{domaenenliste}}"
  120. when:
  121. - domaenenliste is defined
  122. - tunneldigger.instance_per_domain == True
  123. - name: Deploy l2tp_broker.cfg if mode is global
  124. template: src="l2tp_broker.cfg.j2" dest="/srv/tunneldigger/broker/l2tp_broker.cfg"
  125. notify: restart tunneldigger
  126. when:
  127. - domaenenliste is defined
  128. - tunneldigger.instance_per_domain == False
  129. - name: l2tp-bridge einrichten
  130. template: src=l2tp_bridge.j2 dest=/etc/network/interfaces.d/20_l2tp_bridge.cfg
  131. notify: restart networking
  132. when: domaenenliste is defined
  133. - name: Deploy tunneldigger@.service template file
  134. copy: src=tunneldigger@.service dest=/lib/systemd/system/tunneldigger@.service
  135. register: _domain_td_systemd
  136. notify:
  137. - restart tunneldigger per domain
  138. when:
  139. - domaenenliste is defined
  140. - tunneldigger.instance_per_domain == True
  141. - name: Deploy tunneldigger.service file
  142. copy: src=tunneldigger.service dest=/lib/systemd/system/tunneldigger.service
  143. register: _global_td_systemd
  144. notify:
  145. - restart tunneldigger
  146. when:
  147. - domaenenliste is defined
  148. - tunneldigger.instance_per_domain == False
  149. - name: reload systemd
  150. shell: systemctl daemon-reload
  151. when:
  152. - domaenenliste is defined
  153. - _domain_td_systemd.changed or _global_td_systemd.changed
  154. - name: enable all tunneldigger instances
  155. service: name="tunneldigger@{{item.key}}.service" enabled=yes
  156. with_dict: "{{domaenenliste}}"
  157. when:
  158. - domaenenliste is defined
  159. - tunneldigger.instance_per_domain == True
  160. - name: Enable tunneldigger.service if mode is global
  161. service: name="tunneldigger.service" enabled=yes
  162. when:
  163. - domaenenliste is defined
  164. - tunneldigger.instance_per_domain == False