ansible версия: ansible 2.7.7
Juniper.junos 2.1.0
Моя проблема в том, что у меня есть массив интерфейсов коммутатора, в котором я хотел бы найти только физические интерфейсы (например,ge-0/0/0 или ge-0/0/14 или xe-0/0/3)
Я пытался
msg: '{{inter.stdout_lines | regex_search("(ge)") }}
msg: '{{inter.stdout_lines is search("ge") }}'
msg: '{{inter.stdout_lines | search("ge") }}'
Файл Yaml:
---
- name: Get device uptime
hosts:
- switches
- all
connection: local
roles:
- Juniper.junos
gather_facts: no
tasks:
- name: Get uptime
juniper_junos_command:
commands:
- show interfaces terse
register: inter
- name: test iner stdout_lines
debug:
msg: "{{inter.stdout_lines}}"
- name: Print results
debug:
var: inter.stdout_lines
msg: '{{inter | regex_search("(ge)") }}'
Вывод inter.stdout_lines: я знаю, что он вернет что-то, поэтому я знаю, что это не такне пусто.Однако я не уверен, какой тип возвращает inter.stdout_lines.
TASK [test iner stdout_lines] ********************
ok: [192.168.10.254] => {
"msg": [
"",
"Interface Admin Link Proto Local Remote",
"ge-0/0/0 up down",
"ge-0/0/0.0 up down eth-switch",
"pfe-0/0/0 up up",
"pfe-0/0/0.16383 up up inet ",
" inet6 ",
"pfh-0/0/0 up up",
"pfh-0/0/0.16383 up up inet ",
"ge-0/0/1 up down",
"ge-0/0/1.0 up down eth-switch",
"ge-0/0/2 up down",
"ge-0/0/2.0 up down eth-switch",
"ge-0/0/3 up down",
"ge-0/0/3.0 up down eth-switch",
"ge-0/0/4 up up",
"ge-0/0/4.0 up up eth-switch",
"ge-0/0/5 up down",
"ge-0/0/5.0 up down eth-switch",
"ge-0/0/6 up down",
"ge-0/0/6.0 up down eth-switch",
"ge-0/0/7 up down",
"ge-0/0/7.0 up down eth-switch",
"ge-0/0/8 up down",
"ge-0/0/8.0 up down eth-switch",
"ge-0/0/9 up down",
"ge-0/0/9.0 up down eth-switch",
"ge-0/0/10 up down",
"ge-0/0/10.0 up down eth-switch",
"ge-0/0/11 up down",
"ge-0/0/11.0 up down eth-switch",
"ge-0/0/12 up down",
"ge-0/0/12.0 up down eth-switch",
"ge-0/0/13 up down",
"ge-0/0/13.0 up down eth-switch",
"ge-0/0/14 up down",
"ge-0/0/14.0 up down eth-switch",
"ge-0/0/15 up down",
"ge-0/0/15.0 up down eth-switch",
"ge-0/0/16 up down",
"ge-0/0/16.0 up down eth-switch",
"ge-0/0/17 up down",
"ge-0/0/17.0 up down eth-switch",
"ge-0/0/18 up down",
"ge-0/0/18.0 up down eth-switch",
"ge-0/0/19 up down",
"ge-0/0/19.0 up down eth-switch",
"ge-0/0/20 up down",
"ge-0/0/20.0 up down eth-switch",
"ge-0/0/21 up down",
"ge-0/0/21.0 up down eth-switch",
"ge-0/0/22 up down",
"ge-0/0/22.0 up down eth-switch",
"ge-0/0/23 up down",
"ge-0/0/23.0 up down inet 192.168.254.253/30",
"bme0 up up",
"bme0.0 up up inet 128.0.0.1/2 ",
" 128.0.0.4/2 ",
" 128.0.0.16/2 ",
" 128.0.0.63/2 ",
"cbp0 up up",
"dsc up up",
"esi up up",
"gre up up",
"ipip up up",
"irb up up",
"irb.0 up down",
"irb.3 up down inet 192.168.3.254/24 ",
"irb.10 up up inet 192.168.10.254/24",
"irb.11 up down inet 192.168.11.254/24",
"irb.12 up down inet 192.168.12.254/24",
"irb.13 up up inet 192.168.13.254/24",
"irb.14 up down inet 192.168.14.254/24",
"irb.23 up down inet 192.168.23.254/24",
"irb.88 up down inet 192.168.88.254/24",
"jsrv up up",
"jsrv.1 up up inet 128.0.0.127/2 ",
"lo0 up up",
"lo0.16385 up up inet ",
"lsi up up",
"me0 up down",
"me0.0 up down eth-switch",
"mtun up up",
"pimd up up",
"pime up up",
"pip0 up up",
"tap up up",
"vme up down",
"vme.0 up down",
"vtep up up"
]
}
И когда запускается задача Print results
, она возвращает ошибку: Из того, что я могу сказать, эта ошибка является либо пустой переменной, либо неправильнойтипа, но я не знаю, как изменить тип массива.
TASK [Print results] ******************
fatal: [192.168.10.254]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{inter | regex_search(\"(ge)\") }}): expected string or buffer"}
Когда ожидаемый результат выглядит примерно так:
"ge-0/0/1.0 up down eth-switch",
"ge-0/0/2 up down",
"ge-0/0/2.0 up down eth-switch",
"ge-0/0/3 up down",
"ge-0/0/3.0 up down eth-switch",
"ge-0/0/4 up up",
"ge-0/0/4.0 up up eth-switch",
"ge-0/0/5 up down",
"ge-0/0/5.0 up down eth-switch",
"ge-0/0/6 up down",
"ge-0/0/6.0 up down eth-switch",
"ge-0/0/7 up down",
"ge-0/0/7.0 up down eth-switch",
"ge-0/0/8 up down",
"ge-0/0/8.0 up down eth-switch",
"ge-0/0/9 up down",
"ge-0/0/9.0 up down eth-switch",
"ge-0/0/10 up down",
"ge-0/0/10.0 up down eth-switch",
"ge-0/0/11 up down",
"ge-0/0/11.0 up down eth-switch",
"ge-0/0/12 up down",
"ge-0/0/12.0 up down eth-switch",
"ge-0/0/13 up down",
"ge-0/0/13.0 up down eth-switch",
"ge-0/0/14 up down",
"ge-0/0/14.0 up down eth-switch",
"ge-0/0/15 up down",
"ge-0/0/15.0 up down eth-switch",
"ge-0/0/16 up down",
"ge-0/0/16.0 up down eth-switch",
"ge-0/0/17 up down",
"ge-0/0/17.0 up down eth-switch",
"ge-0/0/18 up down",
"ge-0/0/18.0 up down eth-switch",
"ge-0/0/19 up down",
"ge-0/0/19.0 up down eth-switch",
"ge-0/0/20 up down",
"ge-0/0/20.0 up down eth-switch",
"ge-0/0/21 up down",
"ge-0/0/21.0 up down eth-switch",
"ge-0/0/22 up down",
"ge-0/0/22.0 up down eth-switch",
"ge-0/0/23 up down",
"ge-0/0/23.0 up down inet 10.152.254.253/30",
Бонус, если он содержит только интерфейсы без.0
Будет полезна любая помощь.