refactor: reorganize Ansible tasks for better structure and include common package installations
All checks were successful
Nix Format Check / check-format (pull_request) Successful in 40s

This commit is contained in:
2025-01-22 15:11:58 +01:00
parent 596a3574df
commit c651722b73
20 changed files with 125 additions and 186 deletions

View File

@@ -0,0 +1,49 @@
- name: Check if Docker CE is installed
ansible.builtin.command: docker --version
register: docker_check
changed_when: false
failed_when: false
- name: Download Docker installation script
ansible.builtin.get_url:
url: https://get.docker.com
dest: /tmp/get-docker.sh
mode: '0755'
when: docker_check.rc != 0
- name: Install Docker CE
ansible.builtin.shell: bash -c 'set -o pipefail && sh /tmp/get-docker.sh'
args:
creates: /usr/bin/docker
when: docker_check.rc != 0
- name: Add user to docker group
ansible.builtin.user:
name: "{{ ansible_user }}"
groups: docker
append: true
become: true
when: docker_check.rc != 0
- name: Check if docker is running
ansible.builtin.systemd:
name: docker
state: started
enabled: true
become: true
register: docker_service
- name: Reload systemd
ansible.builtin.systemd:
daemon_reload: true
become: true
when: docker_service.changed
- name: Enable and start docker service
ansible.builtin.systemd:
name: docker
state: started
enabled: true
become: true
when: docker_service.changed
notify: Reload systemd

View File

@@ -0,0 +1,38 @@
- name: Include symlinks tasks
ansible.builtin.import_tasks: tasks/global/symlinks.yml
- name: Gather package facts
ansible.builtin.package_facts:
manager: auto
become: true
- name: Include Tailscale tasks
ansible.builtin.import_tasks: tasks/global/tailscale.yml
become: true
- name: Include Rust tasks
ansible.builtin.import_tasks: tasks/global/rust.yml
become: true
- name: Include Docker tasks
ansible.builtin.import_tasks: tasks/global/docker.yml
become: true
- name: Include Ollama tasks
ansible.builtin.import_tasks: tasks/global/ollama.yml
become: true
- name: Ensure common packages are installed
ansible.builtin.package:
name:
- git
- vim
- pipx
- trash-cli
- curl
- wget
state: present
become: true
- name: Include pipx tasks
ansible.builtin.import_tasks: tasks/global/pipx.yml

View File

@@ -0,0 +1,26 @@
- name: Check if Ollama is installed
ansible.builtin.command: ollama --version
register: ollama_check
changed_when: false
failed_when: false
- name: Download Ollama install script
ansible.builtin.get_url:
url: https://ollama.com/install.sh
dest: /tmp/install_ollama.sh
mode: '0755'
when: ollama_check.rc != 0
- name: Install Ollama
ansible.builtin.command: bash -c 'set -o pipefail && sh /tmp/install_ollama.sh'
when: ollama_check.rc != 0
args:
creates: /usr/local/bin/ollama
- name: Check if Ollama is running
ansible.builtin.systemd:
name: ollama
state: started
enabled: true
become: true
register: ollama_service

View File

@@ -0,0 +1,23 @@
- name: List installed pipx packages
ansible.builtin.shell: set -o pipefail && pipx list --short | awk '{print $1}'
register: installed_pipx_packages
changed_when: false
- name: Define desired pipx packages
ansible.builtin.set_fact:
desired_pipx_packages:
- ansible
- ansible-lint
- shyaml
- name: Install/Upgrade pipx packages
community.general.pipx:
name: "{{ item }}"
state: present
loop: "{{ desired_pipx_packages }}"
- name: Remove undesired pipx packages
community.general.pipx:
name: "{{ item }}"
state: absent
loop: "{{ installed_pipx_packages.stdout_lines | difference(desired_pipx_packages) }}"

View File

@@ -0,0 +1,22 @@
- name: Check if Rust is installed
ansible.builtin.shell: source $HOME/.cargo/env && rustc --version
register: rust_check
changed_when: false
failed_when: false
args:
executable: /bin/bash
- name: Download Rust installation script
ansible.builtin.get_url:
url: https://sh.rustup.rs
dest: /tmp/rustup.sh
mode: '0755'
when: rust_check.rc != 0
- name: Install Rust and Cargo
ansible.builtin.shell: |
set -o pipefail
/tmp/rustup.sh -y
args:
creates: ~/.cargo/bin/rustc
when: rust_check.rc != 0

View File

@@ -0,0 +1,49 @@
- name: Set user home directory
ansible.builtin.set_fact:
user_home: "{{ ansible_env.HOME if ansible_user_id == 'root' else lookup('env', 'HOME') }}"
- name: Create basic symlinks
ansible.builtin.file:
src: "{{ item.src | replace('~', user_home) }}"
dest: "{{ item.dest | replace('~', user_home) }}"
state: link
force: true
follow: false
loop:
- { src: "~/dotfiles/config/home-manager", dest: "~/.config/home-manager" }
- { src: "~/dotfiles/vscode/settings.json", dest: "~/.config/Code/User/settings.json" }
- { src: "~/dotfiles/config/ssh/config", dest: "~/.ssh/config" }
- { src: "~/dotfiles/config/ssh/config.d", dest: "~/.ssh/config.d" }
- { src: "~/dotfiles/config/starship.toml", dest: "~/.config/starship.toml" }
- name: Create gitconfig symlink
ansible.builtin.file:
src: "{{ gitconfig_mapping[hostname] | replace('~', user_home) }}"
dest: "{{ user_home }}/.gitconfig"
state: link
force: true
follow: false
vars:
gitconfig_mapping:
mennos-server: "~/dotfiles/config/git/gitconfig.mennos-server"
mennos-desktop: "~/dotfiles/config/git/gitconfig.linux"
mennos-gamingpc: "~/dotfiles/config/git/gitconfig.linux"
mennos-laptop: "~/dotfiles/config/git/gitconfig.linux"
homeserver-pc: "~/dotfiles/config/git/gitconfig.linux"
wsl: "~/dotfiles/config/git/gitconfig.wsl"
- name: Create SSH authorized_keys symlink
ansible.builtin.file:
src: "{{ authorized_keys_mapping[hostname] | replace('~', user_home) }}"
dest: "{{ user_home }}/.ssh/authorized_keys"
state: link
force: true
follow: false
vars:
authorized_keys_mapping:
mennos-server: "~/dotfiles/config/ssh/authorized_keys/mennos-server"
mennos-desktop: "~/dotfiles/config/ssh/authorized_keys/mennos-desktop"
mennos-gamingpc: "~/dotfiles/config/ssh/authorized_keys/mennos-gamingpc"
mennos-laptop: "~/dotfiles/config/ssh/authorized_keys/mennos-laptop"
homeserver-pc: "~/dotfiles/config/ssh/authorized_keys/homeserver-pc"
wsl: "~/dotfiles/config/ssh/authorized_keys/wsl"

View File

@@ -0,0 +1,37 @@
- name: Ensure Tailscale is installed
ansible.builtin.package:
name: tailscale
state: present
become: true
- name: Check if Tailscale is installed
ansible.builtin.command: tailscale
register: tailscale_check
changed_when: false
failed_when: false
- name: Install Tailscale
ansible.builtin.command: tailscale up
args:
creates: /var/lib/tailscale/tailscaled.state
when: tailscale_check.rc != 0
become: true
- name: Check if Tailscale is running
ansible.builtin.command: tailscale status
register: tailscale_status
changed_when: false
failed_when: false
- name: Enable and start Tailscale service
ansible.builtin.systemd:
name: tailscaled
state: started
enabled: true
daemon_reload: true
become: true
- name: Notify user to authenticate Tailscale
ansible.builtin.debug:
msg: "Please authenticate Tailscale by running: sudo tailscale up --operator=$USER"
when: tailscale_status.rc != 0