Initial Lab Setup
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
---
|
||||
- name: Ensure Proxmox GPG key is present (for Raspberry Pi/PBS)
|
||||
ansible.builtin.get_url:
|
||||
url: https://enterprise.proxmox.com/debian/proxmox-release-trixie.gpg
|
||||
dest: /etc/apt/trusted.gpg.d/proxmox-release-trixie.gpg
|
||||
mode: '0644'
|
||||
become: yes # Added
|
||||
when: ansible_distribution == 'Debian'
|
||||
tags: [setup]
|
||||
|
||||
- name: Set hostname
|
||||
ansible.builtin.hostname:
|
||||
name: "{{ inventory_hostname }}"
|
||||
become: yes # Added
|
||||
tags: [identity]
|
||||
|
||||
- name: Update /etc/hosts for FQDN resolution
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/hosts
|
||||
regexp: '^127\.0\.1\.1'
|
||||
line: "127.0.1.1 {{ inventory_hostname }}.{{ domain_name }} {{ inventory_hostname }}"
|
||||
become: yes # Added
|
||||
tags: [identity]
|
||||
|
||||
- name: Check for NetworkManager
|
||||
ansible.builtin.command: systemctl is-active NetworkManager
|
||||
register: nm_status
|
||||
ignore_errors: yes
|
||||
changed_when: false
|
||||
tags: [identity, network]
|
||||
|
||||
- name: Configure NetworkManager Search Domain (Raspberry Pi/mDNS Style)
|
||||
when: nm_status.rc == 0
|
||||
tags: [identity, network]
|
||||
block:
|
||||
- name: Get active connection name
|
||||
ansible.builtin.shell: "nmcli -t -f NAME connection show --active | head -n 1"
|
||||
register: active_conn
|
||||
changed_when: false
|
||||
|
||||
- name: Apply search domain via nmcli
|
||||
ansible.builtin.command: "nmcli connection modify '{{ active_conn.stdout }}' ipv4.dns-search '{{ domain_name }}'"
|
||||
when: active_conn.stdout != ""
|
||||
notify: Reload NetworkManager
|
||||
|
||||
- name: Configure systemd-resolved Search Domain (Vanilla Debian Style)
|
||||
ansible.builtin.ini_file:
|
||||
path: /etc/systemd/resolved.conf
|
||||
section: Resolve
|
||||
option: Domains
|
||||
value: "{{ domain_name }}"
|
||||
become: yes # Added
|
||||
notify: Restart systemd-resolved
|
||||
when: nm_status.rc != 0
|
||||
tags: [identity, network]
|
||||
|
||||
- name: Set system timezone
|
||||
community.general.timezone:
|
||||
name: Europe/Berlin
|
||||
become: yes
|
||||
tags: [localization]
|
||||
|
||||
#- name: Ensure locales are generated
|
||||
# ansible.builtin.locale_gen:
|
||||
# name: en_US.UTF-8
|
||||
# state: present
|
||||
# become: yes
|
||||
# tags: [localization]
|
||||
|
||||
#- name: Set system locale
|
||||
# ansible.builtin.debconf:
|
||||
# name: locales
|
||||
# question: locales/default_environment_locale
|
||||
# value: en_US.UTF-8
|
||||
# vtype: select
|
||||
# become: yes
|
||||
# tags: [localization]
|
||||
|
||||
#- name: Force 24h clock format globally
|
||||
# ansible.builtin.lineinfile:
|
||||
# path: /etc/default/locale
|
||||
# regexp: '^LC_TIME='
|
||||
# line: 'LC_TIME=en_DK.UTF-8' # en_DK is the standard trick for English lang + 24h clock
|
||||
# become: yes
|
||||
# tags: [localization]
|
||||
|
||||
#- name: Set system-wide locale and 24h clock
|
||||
# ansible.builtin.command: >
|
||||
# update-locale LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8
|
||||
# become: yes
|
||||
# changed_when: true
|
||||
|
||||
#- name: Ensure en_US.UTF-8 is generated
|
||||
# ansible.builtin.locale_gen:
|
||||
# name: en_US.UTF-8
|
||||
# state: present
|
||||
# become: yes
|
||||
# tags: [localization]
|
||||
|
||||
- name: Generate required locales
|
||||
ansible.builtin.locale_gen:
|
||||
name: "{{ item }}"
|
||||
state: present
|
||||
become: yes
|
||||
loop:
|
||||
- en_US.UTF-8
|
||||
- en_DK.UTF-8 # We must generate this to use it for the 24h clock
|
||||
tags: [localization]
|
||||
|
||||
|
||||
- name: Force system-wide locale and 24h clock
|
||||
ansible.builtin.command: update-locale LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8
|
||||
become: yes
|
||||
changed_when: true
|
||||
tags: [localization]
|
||||
|
||||
- name: Flush handlers to apply DNS changes immediately
|
||||
ansible.builtin.meta: flush_handlers
|
||||
|
||||
- name: Wait for DNS to be functional
|
||||
ansible.builtin.command: getent hosts google.com
|
||||
register: dns_check
|
||||
until: dns_check.rc == 0
|
||||
retries: 3
|
||||
delay: 5
|
||||
changed_when: false
|
||||
tags: [identity, network]
|
||||
|
||||
- name: Install baseline packages (Unified list)
|
||||
ansible.builtin.apt:
|
||||
name: "{{ common_packages }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
become: yes
|
||||
tags: [packages]
|
||||
|
||||
- name: Install fastfetch (Optional - may not be in legacy repos)
|
||||
ansible.builtin.apt:
|
||||
name:
|
||||
- fastfetch
|
||||
- btm
|
||||
state: present
|
||||
become: yes
|
||||
ignore_errors: yes
|
||||
tags: [packages]
|
||||
|
||||
- name: Configure needrestart for non-interactive automation
|
||||
ansible.builtin.lineinfile:
|
||||
path: /etc/needrestart/needrestart.conf
|
||||
regexp: '^#?\$nrconf{restart}'
|
||||
line: "$nrconf{restart} = 'a';"
|
||||
become: yes
|
||||
tags: [packages, config]
|
||||
|
||||
- name: Ensure discovery services are enabled and running
|
||||
ansible.builtin.service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: yes
|
||||
loop:
|
||||
- avahi-daemon
|
||||
- lldpd
|
||||
become: yes
|
||||
tags: [services]
|
||||
|
||||
- name: Include maintenance tasks
|
||||
ansible.builtin.include_tasks: maintenance.yml
|
||||
tags: [maintenance]
|
||||
Reference in New Issue
Block a user