Re: [ansible-project] Re: Ansible - write only specific output

2019-02-13 Thread Hugo Gonzalez

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 ansible-project+unsubscr...@googlegroups.com 
.
To post to this group, send email to ansible-project@googlegroups.com 
.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a61598d0-736e-43e2-9b10-a07981c9e3cc%40googlegroups.com 
.

For more options, visit https://groups.google.com/d/optout.

--

Hugo F. gonzalez

Senior Consultant

Red Hat LATAM 



--
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
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.


[ansible-project] Re: Ansible - write only specific output

2019-02-13 Thread DM
Thanks to all who responded.

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


- 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





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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/a61598d0-736e-43e2-9b10-a07981c9e3cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [ansible-project] Re: Ansible - write only specific output

2019-02-13 Thread Will McDonald
There's nothing in the ansible CLI that supports explicitly dumping the
output to a file. You could just use a simple shell redirect.

$ ansible -i inventories/aws -m setup all > host-facts.yaml

It's worth noting that the CLI's output doesn't make a distinction between
failed plays or tasks in terms of shell standard in/standard out, all the
output goes to standard out (unless it's something to do with command line
parsing or something lower-level than play execution).

So for example if I remove a pubkey on a host and run the setup module to
gather facts, all the output goes to STDOUT:

xx.xx.xx.xx | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ec2-u...@xx.xx.xx.xx:
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).\r\n",
"unreachable": true
}
yy.yy.yy.yy | SUCCESS => {
"ansible_facts": {
"ansible_all_ipv4_addresses": [
"aa.aa.aa.aa"
],







On Wed, 13 Feb 2019 at 16:46, DM  wrote:

> Thanks I do have the "---" at the top
> When I run t he ansible-playbook how do get all that info to write to a
> file?
> It only shows up on  the cli which I know I can copy and paste to a file,
> but would like to output to a file
>
> Thanks
>
>
>
> 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 ansible-project+unsubscr...@googlegroups.com.
> To post to this group, send email to ansible-project@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/35a3b1fc-da7b-4f4b-a2be-ebd9bf89c49b%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAKtKohTxSeFysALDr%3DjoKRHP_wmiowzB0Kty2oxhoD4%3DDZ%3DOSg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible - write only specific output

2019-02-13 Thread ryad9200000
Hi,

If you want include task in your playbook, you must only do it :

*- include_task: /my_path/.../.../my_file_externe.yml*

This answer answers your question ?

Thanks

Le mercredi 13 février 2019 17:46:48 UTC+1, DM a écrit :
>
> Thanks I do have the "---" at the top
> When I run t he ansible-playbook how do get all that info to write to a 
> file?
> It only shows up on  the cli which I know I can copy and paste to a file, 
> but would like to output to a file
>
> Thanks
>
>
>
> 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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/e3568429-5e57-4f6d-993e-33aad1330940%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible - write only specific output

2019-02-13 Thread DM
Thanks I do have the "---" at the top
When I run t he ansible-playbook how do get all that info to write to a 
file?
It only shows up on  the cli which I know I can copy and paste to a file, 
but would like to output to a file

Thanks



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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/35a3b1fc-da7b-4f4b-a2be-ebd9bf89c49b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[ansible-project] Re: Ansible - write only specific output

2019-02-13 Thread ryad9200000
Hi,

You must create file with extension .yml and beginning this file with "---" 
at the top.
It's simply.

And launch file with line command "ansible-playbook my_file.yml"

This answer answers your question ?

Thanks

Le mercredi 13 février 2019 14:45:06 UTC+1, DM a écrit :
>
> 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 ansible-project+unsubscr...@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/abf9f222-d5fe-4239-8f42-db0197c78d0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.