main.yml 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. ---
  2. - name: Install Ruby
  3. become: true
  4. apt:
  5. pkg:
  6. - ruby
  7. - ruby-dev
  8. - postgresql
  9. - libpq-dev
  10. - python3-psycopg2
  11. - ruby-bundler
  12. - name: Create user
  13. become: true
  14. user:
  15. name: bgplookup
  16. - name: Download BgpLookup
  17. become: true
  18. become_user: bgplookup
  19. git:
  20. repo: https://codeberg.org/mark22k/BgpLookup.git
  21. dest: /home/bgplookup/BgpLookup/
  22. clone: true
  23. force: true
  24. - name: Copy systemd unit
  25. become: true
  26. copy:
  27. src: files/systemd.unit
  28. dest: "/etc/systemd/system/bgplookup.service"
  29. mode: 0664
  30. - name: Copy configuration file
  31. become: true
  32. template:
  33. src: templates/config.json.j2
  34. dest: "/home/bgplookup/BgpLookup/config.json"
  35. mode: 0664
  36. owner: bgplookup
  37. group: bgplookup
  38. - name: Remove lockfile
  39. become: true
  40. file:
  41. path: /home/bgplookup/BgpLookup/Gemfile.lock
  42. state: absent
  43. - name: Select puma as server
  44. become: true
  45. lineinfile:
  46. path: /home/bgplookup/BgpLookup/Gemfile
  47. search_string: "gem 'falcon'"
  48. line: "gem 'puma'"
  49. - name: Disable bundler require
  50. become: true
  51. lineinfile:
  52. path: /home/bgplookup/BgpLookup/config.ru
  53. search_string: "require 'bundler'"
  54. state: absent
  55. - name: Disable bundler require
  56. become: true
  57. lineinfile:
  58. path: /home/bgplookup/BgpLookup/config.ru
  59. search_string: "Bundler.require"
  60. state: absent
  61. - name: Install gems
  62. become: true
  63. become_user: bgplookup
  64. shell: GEM_HOME="$(ruby -e 'puts Gem.user_dir')" PATH="$GEM_HOME/bin:$PATH" bundle install
  65. args:
  66. chdir: /home/bgplookup/BgpLookup
  67. - name: Install cronjob
  68. become: true
  69. copy:
  70. src: files/cronjob.sh
  71. dest: /home/bgplookup/cronjob.sh
  72. mode: 0755
  73. owner: bgplookup
  74. group: bgplookup
  75. - name: Enable cronjob
  76. become: true
  77. become_user: bgplookup
  78. cron:
  79. name: Build relations
  80. minute: "*/30"
  81. job: /home/bgplookup/cronjob.sh
  82. - name: Install gems
  83. become: true
  84. become_user: bgplookup
  85. shell: GEM_HOME="$(ruby -e 'puts Gem.user_dir')" PATH="$GEM_HOME/bin:$PATH" bundle install
  86. args:
  87. chdir: /home/bgplookup/BgpLookup
  88. - name: Enable access to bird registry
  89. become: true
  90. file:
  91. path: /var/lib/bird/
  92. mode: go+x
  93. - name: Enable access to dn42 registry
  94. become: true
  95. file:
  96. path: /var/lib/bird/registry/
  97. mode: go+rx
  98. - name: Enable access to dn42 registry
  99. become: true
  100. file:
  101. path: /var/lib/bird/registry/
  102. mode: go+r
  103. recurse: true
  104. - name: Create PostgreSQL user
  105. become: true
  106. become_user: postgres
  107. community.postgresql.postgresql_user:
  108. name: bgplookup
  109. password: "{{ bgplookup.db.password }}"
  110. - name: Create PostgreSQL database
  111. become: true
  112. become_user: postgres
  113. community.postgresql.postgresql_db:
  114. name: bgplookup
  115. owner: bgplookup
  116. - name: Running Cronjon
  117. become: true
  118. become_user: bgplookup
  119. command: /home/bgplookup/cronjob.sh
  120. args:
  121. chdir: /home/bgplookup/BgpLookup
  122. - name: Enable systemd unit
  123. become: true
  124. systemd:
  125. daemon_reload: true
  126. name: bgplookup.service
  127. masked: false
  128. enabled: true
  129. state: restarted
  130. - name: Enable PostgreSQL
  131. become: true
  132. systemd:
  133. name: postgresql.service
  134. masked: false
  135. enabled: true
  136. state: restarted