|
| 1 | +--- |
| 2 | +- name: Install Node.js 22.x |
| 3 | + block: |
| 4 | + - name: Import the NodeSource Node.js repository signing key |
| 5 | + ansible.builtin.apt_key: |
| 6 | + url: https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key |
| 7 | + state: present |
| 8 | + |
| 9 | + - name: Add the NodeSource Node.js |
| 10 | + ansible.builtin.apt_repository: |
| 11 | + repo: "deb https://deb.nodesource.com/node_21.x nodistro main" |
| 12 | + state: present |
| 13 | + update_cache: yes |
| 14 | + |
| 15 | + - name: Install Node.js |
| 16 | + ansible.builtin.apt: |
| 17 | + name: |
| 18 | + - nodejs |
| 19 | + - npm |
| 20 | + state: present |
| 21 | + update_cache: yes |
| 22 | + |
| 23 | + |
| 24 | +- name: Create a user for the Node.js application |
| 25 | + ansible.builtin.user: |
| 26 | + name: fahrpreis_gatherer |
| 27 | + system: yes |
| 28 | + home: "/opt/fahrpreis_gatherer" |
| 29 | + |
| 30 | +- name: Ensure the application directory exists |
| 31 | + ansible.builtin.file: |
| 32 | + path: "/opt/fahrpreis_gatherer" |
| 33 | + state: directory |
| 34 | + owner: fahrpreis_gatherer |
| 35 | + group: fahrpreis_gatherer |
| 36 | + |
| 37 | +- name: Copy the Node.js application to the server |
| 38 | + ansible.builtin.copy: |
| 39 | + src: "{{ role_path }}/../gatherer_hafas/" |
| 40 | + dest: "/opt/fahrpreis_gatherer" |
| 41 | + owner: fahrpreis_gatherer |
| 42 | + group: fahrpreis_gatherer |
| 43 | + mode: '0755' |
| 44 | +- name: Install Node.js application dependencies with npm |
| 45 | + ansible.builtin.command: |
| 46 | + cmd: npm install |
| 47 | + chdir: /opt/fahrpreis_gatherer |
| 48 | + become: yes |
| 49 | + become_user: fahrpreis_gatherer |
| 50 | + |
| 51 | +- name: Deploy the run script |
| 52 | + ansible.builtin.template: |
| 53 | + src: "run.sh.j2" |
| 54 | + dest: "/opt/fahrpreis_gatherer/run.sh" |
| 55 | + mode: 'o=rx' |
| 56 | + |
| 57 | +- name: Deploy the systemd service template |
| 58 | + ansible.builtin.template: |
| 59 | + src: "fahrpreis_gatherer.service.j2" |
| 60 | + dest: "/etc/systemd/system/fahrpreis_gatherer.service" |
| 61 | + |
| 62 | +- name: Deploy the systemd timer template |
| 63 | + ansible.builtin.template: |
| 64 | + src: "fahrpreis_gatherer.timer.j2" |
| 65 | + dest: "/etc/systemd/system/fahrpreis_gatherer.timer" |
| 66 | + |
| 67 | +- name: Enable and start the timer |
| 68 | + ansible.builtin.systemd: |
| 69 | + name: fahrpreis_gatherer.timer |
| 70 | + enabled: yes |
| 71 | + state: started |
0 commit comments