ansible-homelab/setup.yml

140 lines
3.5 KiB
YAML
Raw Normal View History

---
2024-06-25 06:59:20 +02:00
- name: Setup homelab basics for Debian/Ubuntu systems
2023-06-01 19:02:20 +02:00
hosts: homelab
tasks:
- name: Update cache and all packages
register: updatesys
ansible.builtin.apt:
upgrade: dist
update_cache: true
2024-06-25 06:59:20 +02:00
become: true
- name: Display the last line of the previous task to check the stats
ansible.builtin.debug:
msg: "{{updatesys.stdout_lines|last}}"
- name: Install basic packages
ansible.builtin.apt:
update_cache: true
name:
- apt-file
- apt-listchanges
- apt-utils
- atop
- autoconf
- automake
2024-06-25 06:24:27 +02:00
- borgbackup
- borgmatic
- build-essential
- byobu
- cmake
- curl
- firewalld
- git
- htop
- httpie
- iotop
- less
- libpam-systemd
- lynis
- man-db
- manpages
- nfs-common
- nmon
- pipx
- python3-dev
- python3-pip
- rkhunter
2024-06-25 06:24:27 +02:00
- rclone
- rsync
- unattended-upgrades
- vim
- wget
- zsh
state: present
2024-06-25 06:59:20 +02:00
become: true
- name: Unmask systemd-logind
ansible.builtin.systemd_service:
name: systemd-logind
enabled: true
masked: no
2024-06-25 06:59:20 +02:00
become: true
- name: Ensure systemd-networkd is enabled
ansible.builtin.systemd_service:
name: systemd-networkd
enabled: true
2024-06-25 06:59:20 +02:00
become: true
- name: Ensure NetworkManager is disabled
ansible.builtin.systemd_service:
name: NetworkManager
enabled: false
state: stopped
become: true
- name: Ensure man-db.timer is enabled
ansible.builtin.systemd_service:
name: man-db.timer
enabled: true
2024-06-25 06:59:20 +02:00
become: true
- name: Disable apt downloading translations
ansible.builtin.lineinfile:
path: /etc/apt/apt.conf.d/99translations
create: true
line: 'Acquire::Languages "none";'
owner: root
group: root
mode: "0644"
2024-06-25 06:59:20 +02:00
become: true
2024-06-25 06:59:20 +02:00
- name: Set the shell to zsh for user
ansible.builtin.user:
2024-06-25 06:59:20 +02:00
name: "{{ ansible_user }}"
shell: /usr/bin/zsh
2024-06-25 06:59:20 +02:00
become: true
- name: Ensure glances systemd unit is in place for user
ansible.builtin.blockinfile:
path: "{{ ansible_user_dir }}/.config/systemd/user/glances.service"
create: true
state: present
block: |
[Unit]
Description=Glances
After=network.target
[Service]
ExecStart={{ ansible_user_dir }}/.local/bin/glances -s
Restart=always
RemainAfterExit=no
[Install]
WantedBy=default.target
owner: "{{ ansible_user }}"
group: "{{ ansible_user }}"
mode: "0644"
- name: Check if reboot is required
ansible.builtin.stat:
path: /var/run/reboot-required
register: reboot_required
2024-06-25 06:59:20 +02:00
become: true
- name: Set is_reboot_required fact
ansible.builtin.set_fact:
is_reboot_required: "{{ True if reboot_required.stat.exists else False }}"
- name: Reboot is needed
ansible.builtin.reboot:
reboot_timeout: 120
when: is_reboot_required | bool
2024-06-25 06:59:20 +02:00
become: true
- name: Post-reboot confirmation
ansible.builtin.debug:
msg: "{{ ansible_host }} is now back up and running"
when: is_reboot_required | bool