From 4b5809f4b1deb797486c1538f4f3b1f8c8c0a5d0 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 28 Oct 2019 17:36:06 +0100 Subject: [PATCH] Set the hostname as defined in the inventory. --- library/centos/roles/basic-setup/tasks/main.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/centos/roles/basic-setup/tasks/main.yml b/library/centos/roles/basic-setup/tasks/main.yml index 068c2e5..f4788d0 100644 --- a/library/centos/roles/basic-setup/tasks/main.yml +++ b/library/centos/roles/basic-setup/tasks/main.yml @@ -51,11 +51,16 @@ command: timedatectl set-timezone {{ timezone }} tags: [ 'centos', 'bootstrap' ] -- name: Set the hostname +- name: Set the hostname when explicitly defined hostname: name={{ hostname }} when: hostname is defined tags: [ 'centos', 'bootstrap' ] +- name: Set the hostname as defined in the inventory + hostname: name={{ inventory_hostname }} + when: hostname is not defined + tags: [ 'bootstrap', 'set_hostname' ] + - name: Configure the main interface to set the correct resolvers. dns1 lineinfile: name=/etc/sysconfig/network-scripts/ifcfg-eth0 regexp="^DNS1=" line="DNS1={{ dns1 }}" when: centos_set_dns_servers