(when)当 “string” 字符串 在 'var' 变量中

noteId: WEB8dafd4706acbb2384248ac75f0cc17bd · 原始路径:/ALL/Ansible 自动化管理/使用 when 进行条件控制/(when)当 “string” 字符串 在 'var' 变量中 .note

当 ‘netadm’ 字符串不在 'snmp' 变量中时,才执行任务

剧本:

---- name: snmp hosts: all gather_facts: no tasks: - name: show snmp user ios_command: commands: show snmp user register: snmp - name: config snmp user when netadm is not exist ios_config: lines: - snmp-server group WSC v3 priv - snmp-server user netadm WSC v3 auth sha Lyon!@34 priv aes 256 Lyon!@34 when: '"netadm" not in snmp.stdout[0]'