# Ansible - write only specific output

**URL:** <https://forum.ansible.com/t/ansible-write-only-specific-output/29667>\
**Category:** Ansible Project\
**Created:** [February 13, 2019, 1:45pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667 "2019-02-13T13:45:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![DM11](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@DM11](https://forum.ansible.com/u/DM11)\
**Post date:** [February 13, 2019, 1:45pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667/1 "2019-02-13T13:45:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [February 13, 2019, 3:26pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667/2 "2019-02-13T15:26:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![DM11](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@DM11](https://forum.ansible.com/u/DM11)\
**Post date:** [February 13, 2019, 4:46pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667/3 "2019-02-13T16:46:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ryad9200000](https://avatars.discourse-cdn.com/v4/letter/r/f04885/32.png) [@ryad9200000](https://forum.ansible.com/u/ryad9200000)\
**Post date:** [February 13, 2019, 5:08pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667/4 "2019-02-13T17:08:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Will\_McDonald](https://avatars.discourse-cdn.com/v4/letter/w/f475e1/32.png) [@Will\_McDonald](https://forum.ansible.com/u/Will_McDonald)\
**Post date:** [February 13, 2019, 5:37pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667/5 "2019-02-13T17:37:25Z")

</div>

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-user@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”

],

---

<div class="post-metadata">

**Author:** ![DM11](https://avatars.discourse-cdn.com/v4/letter/d/85e7bf/32.png) [@DM11](https://forum.ansible.com/u/DM11)\
**Post date:** [February 13, 2019, 5:55pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667/6 "2019-02-13T17:55:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [February 13, 2019, 6:37pm UTC](https://forum.ansible.com/t/ansible-write-only-specific-output/29667/7 "2019-02-13T18:37:44Z")

</div>

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:
