From 90d0f790e1f862120b71ad433c89bbeb2aab0ed2 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Mon, 23 Jan 2017 11:28:07 +0100
Subject: [PATCH] Read inventory directly

---
 tasks/more.yml | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/tasks/more.yml b/tasks/more.yml
index 91c1e67..d60a07e 100644
--- a/tasks/more.yml
+++ b/tasks/more.yml
@@ -1,12 +1,7 @@
 ---
 # file: roles/commonconnect/tasks/more.yml
 
-- name: "Read facts"
-  shell: cat ~/.ansible/hostvars/{{ inventory_name }}
-  become: no
-  register: result_facts
-
-- set_fact: facts="{{ result_facts.stdout | from_json }}"
+- set_fact: facts="{{ lookup('file','~/.ansible/hostvars/{{ inventory_name }}') | from_json }}"
 
 - name: "Add Hosts to Hostfile"
   lineinfile:
@@ -14,4 +9,4 @@
     regexp: '.* {{ item }}$'
     line: '{{ facts[item].static_ipv4 }} {{ item }}'
     state: 'present'
-  with_items: '{{ facts }}'
+  with_items: '{{ facts|default([]) }}'
-- 
GitLab