Hello,

I've seen this use case before. It's easier to build the reporting directly into the playbook. You can, for exmaple, create a template that will print what you want for each managed host, and assemble the pieces later:

On 2/13/19 11:55 AM, DM wrote:

The example below is a yaml file to gather data from a Juniper Networks Switch device.
How would you do it this?


I've seen this exact same use case. It's better to build the reporting directly into the playbook. You can, for exaple, create a template that will print what you want for each managed host, and assemble the pieces later:


- name: Get Facts
  hosts: 192.168.1.1
  roles:
    - Juniper.junos
  connection: local
  gather_facts: no
  vars_prompt:
    - name: ADMUSER
      prompt: Username
      private: no
    - name: ADMPASS
      prompt: password
      private: yes
  tasks:
    - name: Retrieve LLDP Neighbor Information Using PyEZ-included Table
      juniper_junos_table:
        file: "lldp.yml"
        table: "RouteTable"
        host: '{{ inventory_hostname }}'
        user: '{{ ADMUSER }}'
        passwd: '{{ ADMPASS }}'
        port: 830
      register: response
    - name: Print response
      debug:
        var: response
    - copy: content="{{ your_json_feed }}" dest=/etc/ansible/file-1



Something like adding a template file like:

|{{ inventory_hostname }} : {{ response }} |

​


Then templating it:

|- name: create part of the report for {{ inventory_hostname }} template: src: my_template.j2 dest: "{{ inventory_hostname.report }}" |
Then you can use the  fetch module to bring it over to the controller and the assemble module to generate a full report.


Hope that helps,


Hugo








On Wednesday, February 13, 2019 at 8:45:06 AM UTC-5, DM wrote:

    How do you write to a file the output of a yaml?

    If possible, how do you only write to a file specific info if?

    Thanks

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a61598d0-736e-43e2-9b10-a07981c9e3cc%40googlegroups.com <https://groups.google.com/d/msgid/ansible-project/a61598d0-736e-43e2-9b10-a07981c9e3cc%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--

Hugo F. gonzalez

Senior Consultant

Red Hat LATAM <https://www.redhat.com>

<https://red.ht/sig>

--
You received this message because you are subscribed to the Google Groups "Ansible 
Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/51742d2b-5715-eb6f-c4cd-e63439534b62%40redhat.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to