On Saturday, 17 February 2018 11.34.19 CET YvanM wrote:
> Thanks for the hint!
>
> I forgot to say that I want to save all Ansible facts *host by host*, so
> "{{ vars }}" contains to much data for me. Here is what I found to remove
> vars from master and other hosts:
Look into the facts caching feature of Ansible, that will only store the gathered facts and not inventory in one file per host.
https://docs.ansible.com/ansible/latest/playbooks_variables.html#fact-caching
> - name: save all facts to host specific file
> copy:
> content: "{{ ansible_delegated_vars[inventory_hostname].vars |
> to_nice_json }}"
> dest: "/some/directory/{{ ansible_fqdn }}"
> delegate_to: localhost
>
> This still contains variables from inventory, but it is better than nothing…
This will also only store the gathered facts and not inventory
- setup:
register: setupvar
- copy:
content: '{{ setupvar.ansible_facts }}'
dest: /some/directory/{{ ansible_fqdn }}
delegate_to: localhost
--
Kai Stian Olstad