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 なしのインターフェイスのみが含まれている場合のボーナス
任意のヘルプが表示されます。