Skip to content

Instantly share code, notes, and snippets.

View trytuna's full-sized avatar

Timo Schrappe trytuna

  • TU Dortmund
  • Germany
View GitHub Profile
@trytuna
trytuna / hosts.yml
Last active June 26, 2018 15:19 — forked from phips/hosts.yml
Ansible setting of hostname from inventory, but ignoring IP addresses
- name: Ensure hostname set
hostname: name={{ inventory_hostname }}
when: inventory_hostname is not match('(\d{1,3}\.){3}\d{1,3}')
- name: Ensure hostname is in /etc/hosts
lineinfile:
dest=/etc/hosts
regexp="^{{ ansible_default_ipv4.address }}.+$"
line="{{ ansible_default_ipv4.address }} {{ ansible_fqdn }} {{ ansible_hostname }}"