Ansible 弃用警告而不是使用 `result|search` 使用 `result is search`,但是如何使用?
Ansible decprecation warning Instead of using `result|search` use `result is search`, but how?
我有一个简单的剧本:
---
- name: cat resolv.conf
telnet:
user: "{{ foxuser }}"
password: "{{ foxpass }}"
login_prompt: "login:"
prompts: "#"
command:
- grep 192.168.178.6 /etc/resolv.conf
register: resolv
changed_when: not( resolv.output | join('') | search('nameserver'))
notify: update resolv.conf
这有效,但会引发弃用警告;
[DEPRECATION WARNING]: Using tests as filters is deprecated. Instead of using `result|search` use `result is search`. This feature will be removed in version 2.9.
我试过了:
changed_when: not('nameserver' in resolv.output )
但这似乎总是正确的,即使 nameserver
在 resolv.output
中也是如此。不知何故,join
似乎是表达式的重要组成部分。
请注意 resolv
包含:
"resolv": {
"changed": false,
"failed": false,
"output": [
" grep 192.168.178.6 /etc/resolv.conf\r\nnameserver 192.168.178.6\r\n[root@foxboard /root]1068#"
]
}
如果没有过滤器,我似乎找不到可行的解决方案。我错过了什么?
我相信这应该有效(模拟测试对我有效):
- name: cat resolv.conf
telnet:
user: "{{ foxuser }}"
password: "{{ foxpass }}"
login_prompt: "login:"
prompts: "#"
command:
- grep 192.168.178.6 /etc/resolv.conf
register: resolv
changed_when: not ( resolv.output | join('') ) is search('nameserver')
notify: update resolv.conf
将搜索功能用作过滤器的一部分似乎是触发弃用警告的原因。
我有一个简单的剧本:
---
- name: cat resolv.conf
telnet:
user: "{{ foxuser }}"
password: "{{ foxpass }}"
login_prompt: "login:"
prompts: "#"
command:
- grep 192.168.178.6 /etc/resolv.conf
register: resolv
changed_when: not( resolv.output | join('') | search('nameserver'))
notify: update resolv.conf
这有效,但会引发弃用警告;
[DEPRECATION WARNING]: Using tests as filters is deprecated. Instead of using `result|search` use `result is search`. This feature will be removed in version 2.9.
我试过了:
changed_when: not('nameserver' in resolv.output )
但这似乎总是正确的,即使 nameserver
在 resolv.output
中也是如此。不知何故,join
似乎是表达式的重要组成部分。
请注意 resolv
包含:
"resolv": {
"changed": false,
"failed": false,
"output": [
" grep 192.168.178.6 /etc/resolv.conf\r\nnameserver 192.168.178.6\r\n[root@foxboard /root]1068#"
]
}
如果没有过滤器,我似乎找不到可行的解决方案。我错过了什么?
我相信这应该有效(模拟测试对我有效):
- name: cat resolv.conf
telnet:
user: "{{ foxuser }}"
password: "{{ foxpass }}"
login_prompt: "login:"
prompts: "#"
command:
- grep 192.168.178.6 /etc/resolv.conf
register: resolv
changed_when: not ( resolv.output | join('') ) is search('nameserver')
notify: update resolv.conf
将搜索功能用作过滤器的一部分似乎是触发弃用警告的原因。