From 61b2d7548a98a71e515617d3d48afc5dcf5580ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pawe=C5=82=20Skrzy=C5=84ski?= <pawel.skrzynski@intel.com>
Date: Mon, 27 Mar 2017 12:27:15 +0200
Subject: [PATCH] Use hostname module to set hostname, and do it for all Os not
 only CoreOS

---
 roles/bootstrap-os/tasks/bootstrap-coreos.yml |  8 --------
 roles/bootstrap-os/tasks/main.yml             | 13 ++++++++++++-
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/roles/bootstrap-os/tasks/bootstrap-coreos.yml b/roles/bootstrap-os/tasks/bootstrap-coreos.yml
index b806d9f6d..892da1c04 100644
--- a/roles/bootstrap-os/tasks/bootstrap-coreos.yml
+++ b/roles/bootstrap-os/tasks/bootstrap-coreos.yml
@@ -50,11 +50,3 @@
     name: "{{ item }}"
   with_items: "{{pip_python_modules}}"
 
-- name: Check configured hostname
-  shell: hostname
-  register: configured_hostname
-  check_mode: no
-
-- name: Assign inventory name to unconfigured hostnames
-  shell: sh -c "echo \"{{inventory_hostname}}\" > /etc/hostname; hostname \"{{inventory_hostname}}\""
-  when: (configured_hostname.stdout == 'localhost')
diff --git a/roles/bootstrap-os/tasks/main.yml b/roles/bootstrap-os/tasks/main.yml
index 4adefb394..73268031e 100644
--- a/roles/bootstrap-os/tasks/main.yml
+++ b/roles/bootstrap-os/tasks/main.yml
@@ -16,4 +16,15 @@
   register: ostree
 
 - set_fact:
-    is_atomic: "{{ ostree.stat.exists }}"
\ No newline at end of file
+    is_atomic: "{{ ostree.stat.exists }}"
+
+- name: Gather nodes hostnames
+  setup:
+    gather_subset: '!all'
+    filter: ansible_hostname
+
+- name: Assign inventory name to unconfigured hostnames
+  hostname:
+    name: "{{inventory_hostname}}"
+  when: ansible_hostname == 'localhost'
+
-- 
GitLab