Files
homelab/ansible/roles/common/tasks/main.yml
T
Adyrem f2321e1f45 Persist static IPs via Ansible to survive VM reboots
common role: add nmcli task that ensures the static IP, gateway, and DNS
are configured in NetworkManager — idempotent, only applies when
network_gateway is defined. Fixes Gitea going offline after reboot
because the NM connection had reverted to DHCP.

group_vars/infra: add network vars (10.10.1.0/24, gw 10.10.1.1)
group_vars/claude_code_vms: add network vars (10.10.2.0/24, gw 10.10.2.1)
  also fix ProxyJump to use adyrem@:2222 (root login was disabled)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-16 04:54:01 +02:00

49 lines
1.3 KiB
YAML

---
- name: Set timezone
community.general.timezone:
name: "{{ timezone }}"
- name: Configure passwordless sudo for wheel
copy:
dest: /etc/sudoers.d/wheel
content: "%wheel ALL=(ALL) NOPASSWD: ALL\n"
mode: "0440"
validate: visudo -cf %s
- name: Ensure admin SSH key is authorized
ansible.posix.authorized_key:
user: "{{ admin_user }}"
key: "{{ admin_ssh_key }}"
state: present
- name: Configure static IP via NetworkManager
ansible.builtin.shell: |
CURRENT=$(nmcli -t -f IP4.ADDRESS dev show {{ network_interface }} 2>/dev/null | cut -d: -f2)
EXPECTED="{{ ansible_host }}/{{ network_prefix }}"
if [ "$CURRENT" != "$EXPECTED" ]; then
CONN=$(nmcli -t -f NAME,DEVICE con show | grep ":{{ network_interface }}$" | cut -d: -f1 | head -1)
nmcli con mod "$CONN" \
ipv4.method manual \
ipv4.addresses "$EXPECTED" \
ipv4.gateway {{ network_gateway }} \
ipv4.dns {{ network_dns }}
nmcli con up "$CONN"
echo changed
else
echo ok
fi
register: _net
changed_when: "'changed' in _net.stdout"
when: network_gateway is defined
- name: Install base packages
community.general.pacman:
name:
- vim
- git
- htop
- curl
- base-devel
state: present
update_cache: true