add ansible

This commit is contained in:
Tomáš Mládek 2024-09-18 22:53:33 +02:00
parent 32f070d58b
commit 5f192240f2
2 changed files with 86 additions and 0 deletions

7
inventory.yml Normal file
View file

@ -0,0 +1,7 @@
all:
hosts:
x2305:
ansible_host: 192.168.10.66
ansible_user: x2305
ansible_become_pass: "x2305"
ansible_become: true

79
setup-autocall.yml Normal file
View file

@ -0,0 +1,79 @@
---
- hosts: all
become: yes
tasks:
- name: Add NodeSource repository for Node.js 18.x
apt_key:
url: "https://deb.nodesource.com/gpgkey/nodesource.gpg.key"
state: present
- name: Add NodeSource repo to sources list
apt_repository:
repo: "deb https://deb.nodesource.com/node_18.x {{ ansible_distribution_release }} main"
state: present
update_cache: yes
- name: Pin Node.js to the NodeSource repository
copy:
dest: /etc/apt/preferences.d/nodesource.pref
content: |
Package: nodejs
Pin: origin deb.nodesource.com
Pin-Priority: 1001
- name: Install Node.js v18
apt:
name: nodejs
state: present
- name: Install pnpm globally using npm
npm:
name: pnpm
global: yes
state: present
- name: Update apt cache and install Git
apt:
name: git
state: present
update_cache: yes
- name: Clone Git repository
become: yes
become_user: "{{ ansible_user }}"
git:
repo: "https://git.thm.place/thm/parsifal.git"
dest: "/home/{{ ansible_user }}/parsifal"
version: "main"
- name: Create the systemd user directory if it doesn't exist
file:
path: "/home/{{ ansible_user }}/.config/systemd/user"
state: directory
owner: "{{ ansible_user }}"
mode: "0755"
- name: Symlink parsifal.service to systemd user directory
file:
src: "/home/{{ ansible_user }}/parsifal/parsifal.service"
dest: "/home/{{ ansible_user }}/.config/systemd/user/parsifal.service"
state: link
- name: Reload systemd for the current user
command: systemctl --user daemon-reload
become: yes
become_user: "{{ ansible_user }}"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ ansible_user_uid }}" # Needed for running systemctl --user
- name: Enable and start the systemd user service (as user)
command: systemctl --user enable --now parsifal
become: yes
become_user: "{{ ansible_user }}"
environment:
XDG_RUNTIME_DIR: "/run/user/{{ ansible_user_uid }}" # Needed for running systemctl --user
# - name: Reload systemd for the current user
# command: loginctl enable-linger {{ ansible_user }}