diff --git a/tasks/more.yml b/tasks/more.yml index 91c1e675803579ea19092595c4ce563adc58d316..d60a07e730242f4c62650fd932f8fae4ebfcec6c 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([]) }}'