Ansible condition when string not matching

删除回忆录丶 提交于 2019-12-02 18:01:37

Try:

when: nginxVersion.stdout != 'nginx version: nginx/1.8.0'

or

when: '"nginx version: nginx/1.8.0" not in nginxVersion.stdout'

Since var is a json string you can parse it to json and access it's keys.

set_fact:
  var_json: "{{ var.stdout|from_json }}"

Then access the json and get the value you want.

when: var_json.nginxVersion.stdout == 'nginx version: nginx/1.8.0'

checkout this link: https://gist.github.com/justinhennessy/28e82c2ec05f9081786a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!