我的策略如下
- name: Juniper SRX Compliance checks
hosts: juniper
gather_facts: false
tasks:
- name: Syslog server check
junos_config:
src: /home/gefelas/ansible_junos/files/syslog_config.txt
diff: true
register: junos_output
- debug:
msg: Syslog server check - This check has failed with the following output({{ junos_output.diff.prepared }})
when: junos_output.changed
- debug:
msg: Syslog server check - This check has passed with the following output({{ junos_output.diff.prepared }})
when: not junos_output.changed它产生输出(在ansible.cfg中使用stdout_callback = community.general.yaml )
msg: |-
Syslog server check - This check has failed with the following output([edit system syslog host 192.168.100.70]
+ interactive-commands any;
[edit system syslog host 192.168.100.70]
+ facility-override local1;
+ log-prefix firewall;
+ source-address 172.16.203.121;
+ explicit-priority;
[edit system syslog]
+ file messages {
+ any critical;
+ authorization info;
+ }
+ file default-log-messages {
+ structured-data;
+ }
+ file sessions {
+ user info;
+ }
+ file interactive-commands {
+ interactive-commands error;
+ })哪个regex模块适合生成以下输出
msg: |-
Syslog server check - This check has failed with the following output
set system syslog archive size 300000
set system syslog archive files 3
set system syslog archive world-readable
set system syslog user * any emergency
set system syslog host 192.168.100.70 any any
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
set system syslog file default-log-messages structured-data
set system syslog file sessions user info
set system syslog file interactive-commands interactive-commands error在剧本中添加一些类似的东西会有什么不同吗?
- set_fact:
junos_output: |
{{ junos_output |
map('regex_replace','.*\\s+( )\\s+.*','\\g<ip>') |
list }} 发布于 2020-07-06 23:10:35
我会给你我最好的技巧,在Ansible中以明文打印路由器的“set”内容。它是肮脏的,它打破了抽象,但它如此方便,以至于我仍然喜欢它。
- name: Print configuration
delegate_to: localhost
shell: "echo '{{ srx_config|join(cr) }}' > /dev/tty"
when: ansible_verbosity > 0
changed_when: false
vars:
cr: '{{ "\n" }}'这里的主要技巧是使用/dev/tty进行输出。如果你运行带有-v选项的playbook,你会在屏幕上的plantext中得到srx_config中的所有行,没有引号,等等。所有你要做的就是调试它,只需登录到控制台并将它们粘贴到“配置”模式。
https://stackoverflow.com/questions/62731942
复制相似问题