Ansible Debug msg redirection as a file
I am looking for some directions to fix an issue where i am not able to save or redirect the Ansible debug output to a JSON or md file.
- debug:
msg:
- "{{ item.results['show ip route'].splitlines() }}"
- "{{ item.results['show ip route summary'].splitlines() }}"
- "{{ item.results['show ip route 0.0.0.0'].splitlines() }}"
loop:
- "{{ out2 }}"
The above mentioned debug module runs at the very end of my playbook. The playbook mainly uses "napalm_cli" network module to collect few outputs from a device. The "napalm_cli" module output is not nicely formatted,so, i have to use splitlines.
Now i am trying to save below output as a file
ok: [lab1-r1] => (item={'failed': False, u'changed': False, u'results': {u'show ip route': u'Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGPn D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area n N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2n E1 - OSPF external type 1, E2 - OSPF external type 2n i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2n ia - IS-IS inter area, * - candidate default, U - per-user static routen o - ODR, P - periodic downloaded static route, H - NHRP, l - LISPn a - application routen + - replicated route, % - next hop override, p - overrides from PfRnnGateway of last resort is not setnn 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masksnC 172.16.10.0/24 is directly connected, GigabitEthernet0/1nL 172.16.10.1/32 is directly connected, GigabitEthernet0/1', u'show ip route summary': u'IP routing table name is default (0x0)nIP routing table maximum-paths is 32nRoute Source Networks Subnets Replicates Overhead Memory (bytes)nconnected 0 2 0 136 360nstatic 0 0 0 0 0napplication 0 0 0 0 0ninternal 1 440nTotal 1 2 0 136 800', u'show ip route 0.0.0.0': u'% Network not in table'}}) => {
"msg": [
[
"Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP",
" D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area ",
" N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2",
" E1 - OSPF external type 1, E2 - OSPF external type 2",
" i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2",
" ia - IS-IS inter area, * - candidate default, U - per-user static route",
" o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP",
" a - application route",
" + - replicated route, % - next hop override, p - overrides from PfR",
"",
"Gateway of last resort is not set",
"",
" 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks",
"C 172.16.10.0/24 is directly connected, GigabitEthernet0/1",
"L 172.16.10.1/32 is directly connected, GigabitEthernet0/1"
],
[
"IP routing table name is default (0x0)",
"IP routing table maximum-paths is 32",
"Route Source Networks Subnets Replicates Overhead Memory (bytes)",
"connected 0 2 0 136 360",
"static 0 0 0 0 0",
"application 0 0 0 0 0",
"internal 1 440",
"Total 1 2 0 136 800"
],
[
"% Network not in table"
]
]
}
Also, i would like to get rid of the content between
ok: [lab1-r1] => napalm_cli non formatted output
"msg": [
Any ideas or thoughts.
Thank You
NN
ansible
add a comment |
I am looking for some directions to fix an issue where i am not able to save or redirect the Ansible debug output to a JSON or md file.
- debug:
msg:
- "{{ item.results['show ip route'].splitlines() }}"
- "{{ item.results['show ip route summary'].splitlines() }}"
- "{{ item.results['show ip route 0.0.0.0'].splitlines() }}"
loop:
- "{{ out2 }}"
The above mentioned debug module runs at the very end of my playbook. The playbook mainly uses "napalm_cli" network module to collect few outputs from a device. The "napalm_cli" module output is not nicely formatted,so, i have to use splitlines.
Now i am trying to save below output as a file
ok: [lab1-r1] => (item={'failed': False, u'changed': False, u'results': {u'show ip route': u'Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGPn D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area n N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2n E1 - OSPF external type 1, E2 - OSPF external type 2n i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2n ia - IS-IS inter area, * - candidate default, U - per-user static routen o - ODR, P - periodic downloaded static route, H - NHRP, l - LISPn a - application routen + - replicated route, % - next hop override, p - overrides from PfRnnGateway of last resort is not setnn 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masksnC 172.16.10.0/24 is directly connected, GigabitEthernet0/1nL 172.16.10.1/32 is directly connected, GigabitEthernet0/1', u'show ip route summary': u'IP routing table name is default (0x0)nIP routing table maximum-paths is 32nRoute Source Networks Subnets Replicates Overhead Memory (bytes)nconnected 0 2 0 136 360nstatic 0 0 0 0 0napplication 0 0 0 0 0ninternal 1 440nTotal 1 2 0 136 800', u'show ip route 0.0.0.0': u'% Network not in table'}}) => {
"msg": [
[
"Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP",
" D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area ",
" N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2",
" E1 - OSPF external type 1, E2 - OSPF external type 2",
" i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2",
" ia - IS-IS inter area, * - candidate default, U - per-user static route",
" o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP",
" a - application route",
" + - replicated route, % - next hop override, p - overrides from PfR",
"",
"Gateway of last resort is not set",
"",
" 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks",
"C 172.16.10.0/24 is directly connected, GigabitEthernet0/1",
"L 172.16.10.1/32 is directly connected, GigabitEthernet0/1"
],
[
"IP routing table name is default (0x0)",
"IP routing table maximum-paths is 32",
"Route Source Networks Subnets Replicates Overhead Memory (bytes)",
"connected 0 2 0 136 360",
"static 0 0 0 0 0",
"application 0 0 0 0 0",
"internal 1 440",
"Total 1 2 0 136 800"
],
[
"% Network not in table"
]
]
}
Also, i would like to get rid of the content between
ok: [lab1-r1] => napalm_cli non formatted output
"msg": [
Any ideas or thoughts.
Thank You
NN
ansible
add a comment |
I am looking for some directions to fix an issue where i am not able to save or redirect the Ansible debug output to a JSON or md file.
- debug:
msg:
- "{{ item.results['show ip route'].splitlines() }}"
- "{{ item.results['show ip route summary'].splitlines() }}"
- "{{ item.results['show ip route 0.0.0.0'].splitlines() }}"
loop:
- "{{ out2 }}"
The above mentioned debug module runs at the very end of my playbook. The playbook mainly uses "napalm_cli" network module to collect few outputs from a device. The "napalm_cli" module output is not nicely formatted,so, i have to use splitlines.
Now i am trying to save below output as a file
ok: [lab1-r1] => (item={'failed': False, u'changed': False, u'results': {u'show ip route': u'Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGPn D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area n N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2n E1 - OSPF external type 1, E2 - OSPF external type 2n i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2n ia - IS-IS inter area, * - candidate default, U - per-user static routen o - ODR, P - periodic downloaded static route, H - NHRP, l - LISPn a - application routen + - replicated route, % - next hop override, p - overrides from PfRnnGateway of last resort is not setnn 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masksnC 172.16.10.0/24 is directly connected, GigabitEthernet0/1nL 172.16.10.1/32 is directly connected, GigabitEthernet0/1', u'show ip route summary': u'IP routing table name is default (0x0)nIP routing table maximum-paths is 32nRoute Source Networks Subnets Replicates Overhead Memory (bytes)nconnected 0 2 0 136 360nstatic 0 0 0 0 0napplication 0 0 0 0 0ninternal 1 440nTotal 1 2 0 136 800', u'show ip route 0.0.0.0': u'% Network not in table'}}) => {
"msg": [
[
"Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP",
" D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area ",
" N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2",
" E1 - OSPF external type 1, E2 - OSPF external type 2",
" i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2",
" ia - IS-IS inter area, * - candidate default, U - per-user static route",
" o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP",
" a - application route",
" + - replicated route, % - next hop override, p - overrides from PfR",
"",
"Gateway of last resort is not set",
"",
" 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks",
"C 172.16.10.0/24 is directly connected, GigabitEthernet0/1",
"L 172.16.10.1/32 is directly connected, GigabitEthernet0/1"
],
[
"IP routing table name is default (0x0)",
"IP routing table maximum-paths is 32",
"Route Source Networks Subnets Replicates Overhead Memory (bytes)",
"connected 0 2 0 136 360",
"static 0 0 0 0 0",
"application 0 0 0 0 0",
"internal 1 440",
"Total 1 2 0 136 800"
],
[
"% Network not in table"
]
]
}
Also, i would like to get rid of the content between
ok: [lab1-r1] => napalm_cli non formatted output
"msg": [
Any ideas or thoughts.
Thank You
NN
ansible
I am looking for some directions to fix an issue where i am not able to save or redirect the Ansible debug output to a JSON or md file.
- debug:
msg:
- "{{ item.results['show ip route'].splitlines() }}"
- "{{ item.results['show ip route summary'].splitlines() }}"
- "{{ item.results['show ip route 0.0.0.0'].splitlines() }}"
loop:
- "{{ out2 }}"
The above mentioned debug module runs at the very end of my playbook. The playbook mainly uses "napalm_cli" network module to collect few outputs from a device. The "napalm_cli" module output is not nicely formatted,so, i have to use splitlines.
Now i am trying to save below output as a file
ok: [lab1-r1] => (item={'failed': False, u'changed': False, u'results': {u'show ip route': u'Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGPn D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area n N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2n E1 - OSPF external type 1, E2 - OSPF external type 2n i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2n ia - IS-IS inter area, * - candidate default, U - per-user static routen o - ODR, P - periodic downloaded static route, H - NHRP, l - LISPn a - application routen + - replicated route, % - next hop override, p - overrides from PfRnnGateway of last resort is not setnn 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masksnC 172.16.10.0/24 is directly connected, GigabitEthernet0/1nL 172.16.10.1/32 is directly connected, GigabitEthernet0/1', u'show ip route summary': u'IP routing table name is default (0x0)nIP routing table maximum-paths is 32nRoute Source Networks Subnets Replicates Overhead Memory (bytes)nconnected 0 2 0 136 360nstatic 0 0 0 0 0napplication 0 0 0 0 0ninternal 1 440nTotal 1 2 0 136 800', u'show ip route 0.0.0.0': u'% Network not in table'}}) => {
"msg": [
[
"Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP",
" D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area ",
" N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2",
" E1 - OSPF external type 1, E2 - OSPF external type 2",
" i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2",
" ia - IS-IS inter area, * - candidate default, U - per-user static route",
" o - ODR, P - periodic downloaded static route, H - NHRP, l - LISP",
" a - application route",
" + - replicated route, % - next hop override, p - overrides from PfR",
"",
"Gateway of last resort is not set",
"",
" 172.16.0.0/16 is variably subnetted, 2 subnets, 2 masks",
"C 172.16.10.0/24 is directly connected, GigabitEthernet0/1",
"L 172.16.10.1/32 is directly connected, GigabitEthernet0/1"
],
[
"IP routing table name is default (0x0)",
"IP routing table maximum-paths is 32",
"Route Source Networks Subnets Replicates Overhead Memory (bytes)",
"connected 0 2 0 136 360",
"static 0 0 0 0 0",
"application 0 0 0 0 0",
"internal 1 440",
"Total 1 2 0 136 800"
],
[
"% Network not in table"
]
]
}
Also, i would like to get rid of the content between
ok: [lab1-r1] => napalm_cli non formatted output
"msg": [
Any ideas or thoughts.
Thank You
NN
ansible
ansible
asked Nov 20 '18 at 7:40
network-Ninjanetwork-Ninja
111
111
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I believe you may want JSON callback (there is also a yaml one, and XMPP, and a whole list of them). The instructions for enabling them are in the fine manual, but the very short version is to just define an environment variable when calling ansible-playbook
:
env ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...
(it works with ansible
, too, if you just wanted to run a single task)
And, while I answered the literal question you had, you may also consider just writing that content out to a file, since it appears it is already JSON, and bypass the use ofdebug:
entirely
– Matthew L Daniel
Nov 20 '18 at 17:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388288%2fansible-debug-msg-redirection-as-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I believe you may want JSON callback (there is also a yaml one, and XMPP, and a whole list of them). The instructions for enabling them are in the fine manual, but the very short version is to just define an environment variable when calling ansible-playbook
:
env ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...
(it works with ansible
, too, if you just wanted to run a single task)
And, while I answered the literal question you had, you may also consider just writing that content out to a file, since it appears it is already JSON, and bypass the use ofdebug:
entirely
– Matthew L Daniel
Nov 20 '18 at 17:10
add a comment |
I believe you may want JSON callback (there is also a yaml one, and XMPP, and a whole list of them). The instructions for enabling them are in the fine manual, but the very short version is to just define an environment variable when calling ansible-playbook
:
env ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...
(it works with ansible
, too, if you just wanted to run a single task)
And, while I answered the literal question you had, you may also consider just writing that content out to a file, since it appears it is already JSON, and bypass the use ofdebug:
entirely
– Matthew L Daniel
Nov 20 '18 at 17:10
add a comment |
I believe you may want JSON callback (there is also a yaml one, and XMPP, and a whole list of them). The instructions for enabling them are in the fine manual, but the very short version is to just define an environment variable when calling ansible-playbook
:
env ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...
(it works with ansible
, too, if you just wanted to run a single task)
I believe you may want JSON callback (there is also a yaml one, and XMPP, and a whole list of them). The instructions for enabling them are in the fine manual, but the very short version is to just define an environment variable when calling ansible-playbook
:
env ANSIBLE_STDOUT_CALLBACK=json ansible-playbook ...
(it works with ansible
, too, if you just wanted to run a single task)
answered Nov 20 '18 at 17:09
Matthew L DanielMatthew L Daniel
8,71612527
8,71612527
And, while I answered the literal question you had, you may also consider just writing that content out to a file, since it appears it is already JSON, and bypass the use ofdebug:
entirely
– Matthew L Daniel
Nov 20 '18 at 17:10
add a comment |
And, while I answered the literal question you had, you may also consider just writing that content out to a file, since it appears it is already JSON, and bypass the use ofdebug:
entirely
– Matthew L Daniel
Nov 20 '18 at 17:10
And, while I answered the literal question you had, you may also consider just writing that content out to a file, since it appears it is already JSON, and bypass the use of
debug:
entirely– Matthew L Daniel
Nov 20 '18 at 17:10
And, while I answered the literal question you had, you may also consider just writing that content out to a file, since it appears it is already JSON, and bypass the use of
debug:
entirely– Matthew L Daniel
Nov 20 '18 at 17:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53388288%2fansible-debug-msg-redirection-as-a-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown