Changes to reference template hostname until the vm is renamed

This commit is contained in:
2026-02-02 16:39:27 -05:00
parent 678625e634
commit 5426456a4d
4 changed files with 77 additions and 3 deletions

View File

@@ -0,0 +1,27 @@
---
- name: Set hostname on newly provisioned machine
hosts: all
become: true
gather_facts: false
tasks:
- name: Set the hostname
ansible.builtin.hostname:
name: "{{ new_hostname }}"
- name: Update /etc/hosts with new hostname
ansible.builtin.lineinfile:
path: /etc/hosts
regexp: '^127\.0\.1\.1'
line: "127.0.1.1 {{ new_hostname }}"
state: present
- name: Restart systemd-hostnamed to apply changes
ansible.builtin.systemd:
name: systemd-hostnamed
state: restarted
ignore_errors: true
- name: Display new hostname
ansible.builtin.debug:
msg: "Hostname set to {{ new_hostname }}"