Closed gefela closed 4 years ago
I have updated the playbook to look like this
name: Juniper SRX configuration compliance checks hosts: juniper gather_facts: false tasks:
set_fact: config_directory: '{{ "/home/myfolder/ansible_junos/files/" }}'
name: Syslog server check junipernetworks.junos.junos_config: src: '{{ config_directory }}/syslog_config.txt' src_format: set comment: Ensure that appropriate Syslog server configured register: junos_output diff: true
debug: var: junos_output
debug: msg: Syslog server check - This check has passed with the following output({{ junos_output.diff.prepared }}) when: not junos_output.changed
debug: msg: Syslog server check - This check has failed with the following output({{ junos_output.diff.prepared }}) when: junos_output.changed
name: Admin credentials check junipernetworks.junos.junos_config: src: '{{ config_directory }}/admin_user.txt' comment: Ensure that Admin user havee been created diff: true register: junos_output1
debug: var: junos_output1 ***failed
debug: msg: Admin credentials check - This check has passed with the following output({{ junos_output1.diff.prepared }}) when: not junos_output1.changed
debug: msg: Admin credentials check - This check has failed with the following output({{ junos_output1.diff.prepared }}) when: junos_output1.changed
name: NTP Server check junipernetworks.junos.junos_config: src: '{{ config_directory }}/NTP_server.txt' comment: Ensure that correct NTP servers has been configured diff: true
debug: var: junos_output2
debug: msg: NTP Server check - This check has passed with the following output({{ junos_output2.diff.prepared }}) when: not junos_output.changed
debug: msg: NTP Server check - This check has failed with the following output({{ junos_output2.diff.prepared }}) when: junos_output.changed
name: Idle timeout check junipernetworks.junos.junos_config: src: '{{ config_directory }}/idle_timeout.txt' comment: Ensure that idle timeout has been configured diff: true
debug: var: junos_output3
debug: msg: Idle timeout check - This check has passed with the following output({{ junos_output3.diff.prepared }}) when: not junos_output.changed
debug: msg: Idle timeout check - This check has failed with the following output({{ junos_output3.diff.prepared }}) when: junos_output.changed
When I run this , it is failing at this
TASK [debug] *** task path: /home/gefelas/ansible_junos/junos_config_new.yml:30 fatal: [172.16.203.121]: FAILED! => msg: |- The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'diff'
The error appears to be in '/home/gefelas/ansible_junos/junos_config_new.yml': line 30, column 5, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
register: junos_output1
- debug:
^ here
PLAY RECAP ***** 172.16.203.121 : ok=5 changed=1 unreachable=0 failed=1 skipped=1 rescued=0 ignored=0
@gefela what I could see here is when you are having an output for msg: Syslog server check - This check has failed with the following output({{ junos_output.diff.prepared }})
, looks like junos_output doesn't have a key called diff. You could have only junos_output to see the whole output.
you could also refer to https://docs.ansible.com/ansible/latest/plugins/callback.html to know more about callback plugins to customize how the output is rendered.
I have used this in my ansible.cfg stdout_callback = community.general.yaml and changed my playbook to this
name: Juniper SRX configuration compliance checks hosts: juniper gather_facts: false tasks:
set_fact: config_directory: '{{ "/home/gefelas/ansible_junos/files/" }}'
name: Syslog server check junipernetworks.junos.junos_config: src: '{{ config_directory }}/syslog_config.txt' src_format: set comment: Ensure that appropriate Syslog server configured register: junos_output diff: true
debug: var: junos_output
debug: msg: Syslog server check - This check has passed with the following output({{ junos_output.diff }}) when: not junos_output.changed
debug: msg: Syslog server check - This check has failed with the following output({{ junos_output.diff.prepared }}) when: junos_output.changed
name: Admin credentials check junipernetworks.junos.junos_config: src: '{{ config_directory }}/admin_user.txt' comment: Ensure that Admin user have been created register: junos_output1 diff: true
debug: msg: Admin credentials check - This check has passed with the following output({{ junos_output1 }}) when: not junos_output1.changed
debug: msg: Admin credentials check - This check has failed with the following output({{ junos_output1 }}) when: junos_output1.changed
name: NTP Server check junipernetworks.junos.junos_config: src: '{{ config_directory }}/NTP_server.txt' comment: Ensure that correct NTP servers has been configured diff: true register: junos_output2
debug: var: junos_output2
debug: msg: NTP Server check - This check has passed with the following output({{ junos_output2 }}) when: not junos_output.changed
debug: msg: NTP Server check - This check has failed with the following output({{ junos_output2 }}) when: junos_output.changed
name: Idle timeout check junipernetworks.junos.junos_config: src: '{{ config_directory }}/idle_timeout.txt' comment: Ensure that idle timeout has been configured diff: true register: junos_output3
debug: var: junos_output3
debug: msg: Idle timeout check - This check has passed with the following output({{ junos_output3 }}) when: not junos_output.changed
debug: msg: Idle timeout check - This check has failed with the following output({{ junos_output3 }}) when: junos_output.changed
I have used junos.output instead but it is not display the output at all
TASK [debug] *** task path: /home/gefelas/ansible_junos/junos_config_new.yml:30 ok: [172.16.203.121] => msg: 'Admin credentials check - This check has passed with the following output({''changed'': False, ''deprecations'': [{''msg'': "Param ''provider'' is deprecated. See the module docs for more information", ''version'': 2.14}], ''failed'': False})'
TASK [debug] *** task path: /home/gefelas/ansible_junos/junos_config_new.yml:33 skipping: [172.16.203.121] =>
@gefela In the task where it's not showing output and displaying skipping [172.16.203.121] =>
,
is because of your condition (when
) hasn't met and that's why it is skipping. Your condition needs to be based on the output you are getting/expecting.
The problem is that when the condition is met , the reason why the sucess or failure is happening is not display exclude the first one
The first check display the following output
TASK [debug] *** task path: /home/gefelas/ansible_junos/junos_config_new.yml:20 ok: [172.16.203.121] => msg: |- Syslog server check - This check has failed with the following output([edit system syslog host 192.168.100.70]
The second one is
ok: [172.16.203.121] => msg: 'Admin credentials check - This check has passed with the following output({''changed'': False, ''deprecations'': [{''msg'': "Param ''provider'' is deprecated. See the module docs for more information", ''version'': 2.14}], ''failed'': False})'
The third one is
TASK [debug] *** task path: /home/gefelas/ansible_junos/junos_config_new.yml:48 ok: [172.16.203.121] => msg: 'NTP Server check - This check has failed with the following output({''changed'': False, ''deprecations'': [{''msg'': "Param ''provider'' is deprecated. See the module docs for more information", ''version'': 2.14}], ''failed'': False})'
@gefela it is the deprecation warning for connection local as connection local support has been deprecated for module
could you try with netconf connection by changing
ansible_connection=ansible.netcommon.netconf
this should work fine and display the proper output.
Hi!
Thanks very much for your interest in Ansible. It sincerely means a lot to us.
This appears to be a user question, and we'd like to direct these kinds of things to either the mailing list or the IRC channel.
IRC: #ansible on irc.freenode.net mailing list: https://groups.google.com/forum/#!forum/ansible-project If you can stop by there, we'd appreciate it. This allows us to keep the issue tracker for bugs, pull requests, RFEs and the like.
Thank you once again and we look forward to seeing you on the list or IRC. Thanks!
SUMMARY
junos_config: junos playbook not displaying diff output correctly and msg': \"Param 'provider' is deprecated is displayed
ISSUE TYPE
COMPONENT NAME
junipernetworks.junos.junos_config
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
OS = Redhat v 8.1
STEPS TO REPRODUCE
EXPECTED RESULTS
The results should be as a result of comparing the src directory against the configuration of juniper vsrx ... The src files are similar to these https://github.com/gefela/ansible_junos/tree/master/files However the output is not displayed correctly
ACTUAL RESULTS
When I run this command .
ansible-playbook -i inventory junos_config_new.yml --check -vvv
I get the following error message .
What do I have to do to displayed the output in a human readable format How do I get it to remove the extra spaces ( \n \n+ ) and text and get it to look like this ( human readable) below ?
set system syslog host 192.168.100.70 interactive-commands any set system syslog host 192.168.100.70 facility-override local1 set system syslog host 192.168.100.70 log-prefix firewall set system syslog host 192.168.100.70 source-address 172.16.203.121 set system syslog host 192.168.100.70 explicit-priority set system syslog file messages any critical set system syslog file messages authorization info
I have tried using these examples in the past
https://serverfault.com/questions/640130/display-output-with-ansible https://stackoverflow.com/questions/34188167/ansible-print-message-debug-msg-line1-n-var2-n-line3-with-var3