-
-
Save trytuna/8f9ae7f6742d0e9ef0d80e55793c59b1 to your computer and use it in GitHub Desktop.
Ansible setting of hostname from inventory, but ignoring IP addresses
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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 }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment