Initial Lab Setup
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
- name: Install base packages
|
||||
package:
|
||||
name: [vim, git, curl, avahi-daemon]
|
||||
state: present
|
||||
|
||||
- name: Set hostname
|
||||
hostname:
|
||||
name: "{{ inventory_hostname }}"
|
||||
|
||||
- name: Update /etc/hosts for FQDN resolution
|
||||
lineinfile:
|
||||
path: /etc/hosts
|
||||
regexp: '^127\.0\.1\.1'
|
||||
line: "127.0.1.1 {{ inventory_hostname }}.{{ domain_name }} {{ inventory_hostname }}"
|
||||
|
||||
- name: Check for NetworkManager
|
||||
command: systemctl is-active NetworkManager
|
||||
register: nm_status
|
||||
ignore_errors: yes
|
||||
changed_when: false
|
||||
|
||||
- name: Configure NetworkManager Search Domain (Raspberry Pi Style)
|
||||
block:
|
||||
- name: Get active connection name
|
||||
shell: "nmcli -t -f NAME connection show --active | head -n 1"
|
||||
register: active_conn
|
||||
changed_when: false
|
||||
|
||||
- name: Apply search domain via nmcli
|
||||
command: "nmcli connection modify '{{ active_conn.stdout }}' ipv4.dns-search '{{ domain_name }}'"
|
||||
when: active_conn.stdout != ""
|
||||
notify: Reload NetworkManager
|
||||
when: nm_status.rc == 0
|
||||
|
||||
- name: Configure systemd-resolved Search Domain (Vanilla Debian Style)
|
||||
ini_file:
|
||||
path: /etc/systemd/resolved.conf
|
||||
section: Resolve
|
||||
option: Domains
|
||||
value: "{{ domain_name }}"
|
||||
notify: Restart systemd-resolved
|
||||
when: nm_status.rc != 0
|
||||
- name: Flush handlers to apply DNS changes immediately
|
||||
meta: flush_handlers
|
||||
|
||||
- name: Wait for DNS to be functional
|
||||
command: getent hosts google.com
|
||||
register: dns_check
|
||||
until: dns_check.rc == 0
|
||||
retries: 3
|
||||
delay: 5
|
||||
|
||||
- name: Install merged baseline packages
|
||||
apt:
|
||||
name: "{{ common_packages }}"
|
||||
state: present
|
||||
update_cache: yes
|
||||
cache_valid_time: 3600
|
||||
become: yes
|
||||
|
||||
- name: Configure needrestart for non-interactive automation
|
||||
lineinfile:
|
||||
path: /etc/needrestart/needrestart.conf
|
||||
regexp: '^#?\$nrconf{restart}'
|
||||
line: "$nrconf{restart} = 'a';"
|
||||
become: yes
|
||||
|
||||
- name: Ensure discovery services are enabled and running
|
||||
service:
|
||||
name: "{{ item }}"
|
||||
state: started
|
||||
enabled: yes
|
||||
loop:
|
||||
- avahi-daemon
|
||||
- lldpd
|
||||
become: yes
|
||||
- name: Include maintenance tasks
|
||||
include_tasks: maintenance.yml
|
||||
Reference in New Issue
Block a user