common/tasks/hostname.yaml
Simon Cornet 210fbd68f4
All checks were successful
ci/woodpecker/push/linting Pipeline was successful
chore: cleanup tag mess
Tag only in main.yaml, tasks inherit them.
2026-05-20 09:40:02 +02:00

16 lines
540 B
YAML

---
# set hostname
- name: "set hostname"
ansible.builtin.hostname:
name: "{{ set_hostname | default(inventory_hostname_short) }}"
use: "{{ hostname_use_method }}"
# manage /etc/hosts
- name: "manage /etc/hosts file for hostname"
ansible.builtin.lineinfile:
path: "/etc/hosts"
regexp: '^{{ ansible_facts["default_ipv4"].address }}\s+.*{{ inventory_hostname_short }}.*$'
line: "{{ ansible_facts['default_ipv4'].address }} {{ inventory_hostname }} {{ inventory_hostname_short }}"
backup: true
tags: "hostfile"